practiceModule.directive("practiceChargeitemDeductionStepView", ["$log", "$timeout", "$modal", "$q", "aresNotification", function(n, t) {
    "use strict";
    return {
        scope: {
            deductionStep: "=",
            productList: "=",
            followupRuleLites: "=",
            isConnectYongyouHrp: "=",
            isShowAutoDeductionExecute: "=?",
            isChargeItemEditAllowed: "=?"
        },
        restrict: "E",
        templateUrl: "/app/practice/components/practice-chargeItem-deduction-step/practice-chargeItem-deduction-step-view.html",
        link: function(n, i) {
            var r = !0,
                u = null,
                f = function() {
                    u = i.find(".search-products").kendoItemNameCodeFilterComboBox({
                        filter: "contains",
                        placeholder: "物品名称/拼首码/品牌/规格/内部编码/条形码",
                        dataTextField: "name",
                        dataValueField: "id",
                        headerTemplate: '<div class="dropdown-select-head" style=" border-width: 0 0 1px 0;text-transform: uppercase;background-color:#f4f4f4;border-bottom: 1px solid #e3e3e3;" ><span style=" display: inline-block;width:155px;max-width:180px;margin-left:5px">项目名称<\/span><span style=" display: inline-block;width:115px;max-width:140px;margin-left:5px">品牌<\/span><span style=" display: inline-block;width:115px;max-width:140px;margin-left:5px">规格名称<\/span><span style=" display: inline-block;width:55px;max-width:140px;margin-left:5px">单位<\/span><\/div>',
                        template: '<span class="dropdown-select-text" style=" display: inline-block;width:155px;max-width:180px;">#: data.name #<\/span><span class="dropdown-select-text" style=" display: inline-block;width:125px;max-width:150px;">#: data.producer ==null ? "" :data.producer #<\/span><span class="dropdown-select-text" style=" display: inline-block;width:125px;max-width:150px;">#: data.specification ==null ? "" :data.specification #<\/span><span class="dropdown-select-text" style=" display: inline-block;width:55px;max-width:80px;">#: data.unit ==null ? "" :data.unit #<\/span>',
                        height: 370,
                        select: function(t) {
                            var i = this.dataItem(t.item.index()),
                                u = this.text();
                            n.searchText = u;
                            r = i && (i.name && i.name.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.specification && i.specification.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.producer && i.producer.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.pinyin && i.pinyin.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.barCode && i.barCode.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.itemName && i.itemName.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.producerBarCode && i.producerBarCode.toLowerCase().indexOf(u.toLowerCase()) > -1 || i.code && i.code.toLowerCase().indexOf(u.toLowerCase()) > -1)
                        },
                        change: function() {
                            var f = null,
                                u = n.searchText || this.text(),
                                o, s, h;
                            if (r && this.selectedIndex >= 0 ? f = this.dataItem(this.selectedIndex) : u && u.length > 0 && (o = _.filter(n.products, function(n) {
                                    return n.producerBarCode == u || n.code == u
                                }), f = o.length == 1 ? o[0] : null, f || r ? o.length > 1 && (this.text(u), this.search(u), t(function() {
                                    e()
                                }, 500)) : (this.text(u), this.search(u))), r = !0, f) {
                                if (r = !1, s = _.find(n.deductionStep.stepProducts, function(n) {
                                        return n.productId == f.id
                                    }), s) return;
                                h = {
                                    chargeItemId: n.deductionStep.chargeItemId,
                                    chargeItemDeductionStepId: n.deductionStep.id,
                                    productId: f.id,
                                    defaultCount: null,
                                    syncSourceId: 1,
                                    product: f
                                };
                                n.deductionStep.stepProducts || (n.deductionStep.stepProducts = []);
                                n.deductionStep.stepProducts.push(h);
                                n.$apply();
                                i.find(".default-count").focus()
                            }
                            this.select(-1)
                        }
                    }).data("kendoItemNameCodeFilterComboBox")
                },
                e = function() {
                    var n = i.find(".search-products").data("kendoItemNameCodeFilterComboBox");
                    n.open()
                },
                o = function() {
                    n.isShowProductTable = !0;
                    t(function() {
                        f();
                        u && u.setDataSource(n.productList)
                    }, 200)
                },
                s = function(t) {
                    for (var r, i = 0; i < n.deductionStep.stepProducts.length; i++)
                        if (r = n.deductionStep.stepProducts[i], r.product.id == t) {
                            n.deductionStep.stepProducts.splice(i, 1);
                            break
                        }
                },
                h = function(n, i) {
                    t(function() {
                        n.defaultCount || (n.defaultCount = 0);
                        var t = parseInt(n.defaultCount) + i;
                        n.defaultCount = t;
                        n.defaultCount < 1 && (n.defaultCount = 1)
                    })
                },
                c = function(n) {
                    var t = n.keyCode;
                    (t < 48 || t > 57) && t != 8 && n.preventDefault();
                    t == 13 && i.find("#products").focus()
                };
            (function() {
                var i = angular.copy(n.productList);
                n.isContainProducts = n.deductionStep && n.deductionStep.stepProducts && n.deductionStep.stepProducts.length > 0;
                n.showProductTable = o;
                n.isShowProductTable = n.isContainProducts;
                n.deleteDeductionStepProduct = s;
                n.onEditTakeCount = h;
                n.onListenNumber = c;
                t(function() {
                    n.isContainProducts && (f(), u && u.setDataSource(n.productList))
                })
            })()
        }
    }
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.templateUrl = "/app/practice/components/practice-payment-scenario-config/practice-payment-scenario-config-view.html";
            this.controller = "PaymentScenarioConfigCtrl";
            this.scope = {
                scenarioConfigs: "=",
                isOnlyShow: "=?"
            };
            this.link = function() {}
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("paymentScenarioConfigView", Ares.tsDirective(n))
})(practice || (practice = {}));
var practice;
(function() {
    "use strict";
    var n = function() {
        function n(n) {
            var t;
            this.$scope = n;
            this._paymentScenarios = (t = {}, t[0] = "未知", t[1] = "普通诊疗账单收费", t[2] = "储值卡充值", t[3] = "现金券售卖", t[4] = "折扣券售卖", t[5] = "套餐券售卖", t[6] = "划扣项目账单收费", t[7] = "划扣项目执行确认", t[8] = "诊疗预收款收费", t[9] = "折扣券售卖进预收", t[10] = "套餐券售卖进预收", t[11] = "不记名卡交易", t[12] = "挂号费预收", t[13] = "挂号费预收确认", t);
            this.initData()
        }
        return n.prototype.initData = function() {
            var n = this;
            this.$scope.scenarioConfigs && this.$scope.scenarioConfigs.forEach(function(t) {
                t.scenarioName = n._paymentScenarios[t.scenario]
            })
        }, n.$inject = ["$scope"], n
    }();
    practiceModule.controller("PaymentScenarioConfigCtrl", Ares.tsController(n))
})(practice || (practice = {}));
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.templateUrl = "/app/practice/components/practice-payment-type-category-description/practice-payment-type-category-description-view.html";
            this.scope = {
                currentCategoryName: "=?",
                currentCategoryPaymentTypes: "=?"
            };
            this.link = function() {}
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("paymentTypeCategoryDescriptionView", Ares.tsDirective(n))
})(practice || (practice = {}));
practiceModule.directive("practicePaymentTypeConfigView", ["$log", "$timeout", "$modal", "$q", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    return {
        scope: {
            paymentTypeConfig: "=",
            updatePaymentTypeConfigPromise: "=?",
            isEnableGiftCard: "=",
            isEditAllowed: "=",
            isDisabled: "=",
            isUpgradeStart: "=",
            onEnableChanged: "=",
            paymentType: "="
        },
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/components/practice-payment-type-config/practice-payment-type-config-view.html",
        link: function(n) {
            var i = [charge.InternalPaymentType.Shangbao, charge.InternalPaymentType.Yibao, charge.InternalPaymentType.CashCoupon, charge.InternalPaymentType.GiftCardAmount, charge.SplitPaymentTypeConfig.AdvancePaidShare, charge.SplitPaymentTypeConfig.AdvanceGiftShare, charge.SplitPaymentTypeConfig.GiftCardPaidShare, charge.SplitPaymentTypeConfig.GiftCardGiftShare, charge.SplitPaymentTypeConfig.CashCouponPaidShare, charge.SplitPaymentTypeConfig.CashCouponGiftShare, charge.SplitPaymentTypeConfig.AlipayBpCost, charge.SplitPaymentTypeConfig.AlipayBpShare, charge.SplitPaymentTypeConfig.WeInsuranceCost, charge.SplitPaymentTypeConfig.WeInsuranceShare, charge.SplitPaymentTypeConfig.CustomOrderCost, charge.SplitPaymentTypeConfig.CustomOrderShare, charge.SplitPaymentTypeConfig.JDCost, charge.SplitPaymentTypeConfig.JDShare],
                f = [charge.SplitPaymentTypeConfig.AdvancePaidShare, charge.SplitPaymentTypeConfig.AdvanceGiftShare, charge.SplitPaymentTypeConfig.GiftCardPaidShare, charge.SplitPaymentTypeConfig.GiftCardGiftShare, charge.SplitPaymentTypeConfig.CashCouponPaidShare, charge.SplitPaymentTypeConfig.CashCouponGiftShare, charge.SplitPaymentTypeConfig.AlipayBpCost, charge.SplitPaymentTypeConfig.AlipayBpShare, charge.SplitPaymentTypeConfig.WeInsuranceCost, charge.SplitPaymentTypeConfig.WeInsuranceShare, charge.SplitPaymentTypeConfig.CustomOrderCost, charge.SplitPaymentTypeConfig.CustomOrderShare, charge.SplitPaymentTypeConfig.JDCost, charge.SplitPaymentTypeConfig.JDShare],
                e = [charge.SplitPaymentTypeConfig.AdvancePaidShare, charge.SplitPaymentTypeConfig.AdvanceGiftShare, charge.SplitPaymentTypeConfig.GiftCardPaidShare, charge.SplitPaymentTypeConfig.GiftCardGiftShare, charge.SplitPaymentTypeConfig.CashCouponPaidShare, charge.SplitPaymentTypeConfig.CashCouponGiftShare, charge.SplitPaymentTypeConfig.AlipayBpCost, charge.SplitPaymentTypeConfig.AlipayBpShare, charge.SplitPaymentTypeConfig.WeInsuranceCost, charge.SplitPaymentTypeConfig.WeInsuranceShare, charge.SplitPaymentTypeConfig.CustomOrderCost, charge.SplitPaymentTypeConfig.CustomOrderShare, charge.SplitPaymentTypeConfig.JDCost, charge.SplitPaymentTypeConfig.JDShare, charge.InternalPaymentType.HuifuAcquire, charge.SplitPaymentTypeConfig.HuifuScanWeixin, charge.SplitPaymentTypeConfig.HuifuScanAliPay, charge.SplitPaymentTypeConfig.HuifuScanUniPay, charge.SplitPaymentTypeConfig.HuifuBoxWeixin, charge.SplitPaymentTypeConfig.HuifuBoxAliPay, charge.SplitPaymentTypeConfig.HuifuBoxUniPay, charge.InternalPaymentType.UniPayPos, charge.InternalPaymentType.UniPayQrcode, charge.InternalPaymentType.UniPayBox, charge.SplitPaymentTypeConfig.UniPayBoxWeixin, charge.SplitPaymentTypeConfig.UniPayBoxAliPay, charge.SplitPaymentTypeConfig.UniPayBoxUniPay, charge.InternalPaymentType.ShanxiHealth, charge.InternalPaymentType.ScrmPay],
                t = function() {
                    var t = r.defer();
                    return n.paymentTypeConfig.name != "" ? n.updatePaymentTypeConfigPromise(n.paymentTypeConfig).then(function(i) {
                        n.paymentTypeConfig.id = i.id;
                        t.resolve()
                    }, function() {
                        u.error("支付方式配置更新失败！");
                        t.reject()
                    }) : t.resolve(), t.promise
                },
                o = function() {
                    if (n.isEditAllowed(n.paymentType) && !n.isDisabled) {
                        var i = n.paymentTypeConfig.isEnabled;
                        if (i && !l()) {
                            u.error("所选支付方式不可禁用！");
                            return
                        }
                        if (!i && !a()) {
                            u.error("所选支付方式不可启用！");
                            return
                        }
                        n.paymentTypeConfig.isEnabled = !n.paymentTypeConfig.isEnabled;
                        t().then(function() {
                            if (n.onEnableChanged && _.isFunction(n.onEnableChanged)) n.onEnableChanged(n.paymentTypeConfig)
                        }, function() {
                            n.paymentTypeConfig.isEnabled = !n.paymentTypeConfig.isEnabled
                        })
                    }
                },
                s = function() {
                    t().then(null, function() {
                        n.paymentTypeConfig.isInCashFlow = !n.paymentTypeConfig.isInCashFlow
                    })
                },
                h = function() {
                    t().then(null, function() {
                        n.paymentTypeConfig.isIncome = !n.paymentTypeConfig.isIncome
                    })
                },
                c = function() {
                    t().then(null, function() {
                        n.paymentTypeConfig.isInPerformance = !n.paymentTypeConfig.isInPerformance
                    })
                },
                l = function() {
                    return n.paymentTypeConfig.scenario == 1 && (n.isEnableGiftCard && n.paymentTypeConfig.name == charge.InternalPaymentType.GiftCard || i.indexOf(n.paymentTypeConfig.name) >= 0 || /^团购券\//.test(n.paymentTypeConfig.name)) ? !1 : !0
                },
                a = function() {
                    var t = n.paymentTypeConfig.name;
                    return n.paymentTypeConfig.scenario == 2 && f.indexOf(t) >= 0 || n.paymentTypeConfig.scenario == 3 && e.indexOf(t) >= 0 ? !1 : !0
                },
                v = function() {
                    n.paymentTypeConfig && (n.isInComeCheckboxId = n.paymentTypeConfig.name + "_is_income_" + n.paymentTypeConfig.scenario, n.isInCashflowCheckboxId = n.paymentTypeConfig.name + "_is_incashflow_" + n.paymentTypeConfig.scenario, n.isInPerformanceboxId = n.paymentTypeConfig.name + "_is_inperformance_" + n.paymentTypeConfig.scenario)
                };
            (function() {
                n.onSwitchClick = o;
                n.onInCashFlowClicked = s;
                n.onInComeClicked = h;
                n.onInPerformanceClicked = c;
                v()
            })()
        }
    }
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.templateUrl = "/app/practice/components/practice-payment-type-group/practice-payment-type-group-view.html";
            this.scope = {
                paymentTypes: "=",
                hasEditPermission: "=",
                isEditEnabled: "=",
                editPaymentTypeMethod: "=",
                isDeleteEnabled: "=",
                deletePaymentTypeMethod: "=",
                switchPaymentTypeEnabled: "=",
                hiddenPaytypeNames: "="
            };
            this.link = function() {
                (function() {})()
            }
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("practicePaymentTypeGroupView", Ares.tsDirective(n))
})(practice || (practice = {}));
practiceModule.directive("practicePaymentTypeNameView", ["$log", "$timeout", "$modal", "aresNotification", function(n, t, i, r) {
    "use strict";
    return {
        scope: {
            paymentType: "=",
            updatePaymentTypePromise: "=?",
            onPaymentTypeEdit: "=?",
            onCompletePaymentTypeEdit: "=?",
            propertoryName: "@",
            refreshMethod: "=?",
            isEditAllowed: "=",
            defaultPaymentTypeNames: "="
        },
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/components/practice-payment-type-name/practice-payment-type-name-view.html",
        link: function(n, t) {
            var u = function() {
                    n.onPaymentTypeEdit && n.onPaymentTypeEdit() && (n.viewStatus = "edit")
                },
                f = function() {
                    if (e())
                        if (n.paymentType[n.propertoryName] != n.originPropertoryVlaue) {
                            if (n.propertoryName == "name" && n.defaultPaymentTypeNames.indexOf(n.paymentType[n.propertoryName]) > 0) {
                                r.error("系统默认支付方式不允许手动添加！");
                                return
                            }
                            n.updatePaymentTypePromise ? n.updatePaymentTypePromise(n.paymentType).then(function() {
                                n.viewStatus = "show";
                                i()
                            }, function() {
                                n.paymentType[n.propertoryName] = n.originPropertoryVlaue
                            }) : (n.paymentType[n.propertoryName] = n.originPropertoryVlaue, n.viewStatus = "show", i(), n.onCompletePaymentTypeEdit())
                        } else n.viewStatus = "show", n.onCompletePaymentTypeEdit()
                },
                e = function() {
                    var t, i;
                    if (n.propertoryName == "itemCode") {
                        if (t = n.paymentType[n.propertoryName], t && t.length > 50) return r.error("支付方式编码长度不能超过50"), !1
                    } else if (n.propertoryName == "itemName" && (i = n.paymentType[n.propertoryName], i && i.length > 512)) return r.error("支付方式名称长度不能超过512"), !1;
                    return !0
                },
                i = function() {
                    n.propertoryName !== "itemName" && (n.paymentType.itemName == "储值卡本金" || n.paymentType.itemName == "储值卡馈赠金") && n.refreshMethod != null && _.isFunction(n.refreshMethod) && n.refreshMethod()
                },
                o = function() {
                    n.paymentType[n.propertoryName] = n.originPropertoryVlaue;
                    n.viewStatus = "show";
                    n.onCompletePaymentTypeEdit()
                },
                s = function() {
                    n.paymentType.id ? n.viewStatus = "show" : (n.viewStatus = "edit", t.find(".name-show input").focus())
                };
            (function() {
                n.editPaymentType = u;
                n.savePaymentTypeName = f;
                n.cancelSavePaymentTypeName = o;
                n.originPropertoryVlaue = n.paymentType[n.propertoryName];
                s()
            })()
        }
    }
}]);
practiceModule.controller("ApptInventoryItemsBaseSettingCtrl", ["$log", "$scope", "apptInventorySvc", "aresNotification", "enums", "aresDialog", "officeOptionSvc", function(n, t, i, r, u, f) {
    "use strict";
    var e = function(r) {
            i.getApptInventorySetting(r).success(function(n) {
                t.baseSetting = n;
                t.initialized || (t.apptInventoryCalcMode = n.apptInventoryCalcMode, t.initialized = !0);
                t.baseSettingCache = angular.copy(t.baseSetting)
            }).error(function(t) {
                n.debug(t);
                f.info("信息", "渠道服务数据配置获取失败")
            })
        },
        o = function() {
            t.baseSetting.apptInventoryCalcMode = t.apptInventoryCalcMode;
            i.saveApptInventorySetting(t.baseSetting).success(function() {
                r.success("修改成功")
            })
        };
    (function() {
        t.initialized = !1;
        t.apptInventoryCalcMode = 0;
        t.saveApptInventorysBaseSetting = o;
        t.initApptInventorysBaseSetting = e
    })()
}]);
practiceModule.controller("ApptInventoryItemsMappingCtrl", ["$log", "$scope", "dataDicSvc", "apptInventorySvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    var f = function(n) {
            i.doctorDic.load().then(function(i) {
                var f = [],
                    u, e;
                for (f.push({
                        id: 0,
                        name: "全部"
                    }), i.push({
                        id: 0,
                        name: "全部"
                    }), u = i.length - 1; u >= 0; u--) i[u].show === !0 && i[u].isInactive === !1 && f.push(i[u]);
                t.doctors = f;
                e = !1;
                r.list(n).then(function(n) {
                    for (var f, r, o, u = 0; u < n.data.length; u++) {
                        for (f = n.data[u].itemProviders, r = 0; r < f.length; r++)
                            for (o = 0; o < i.length; o++)
                                if (i[o].id === parseInt(f[r].providerId)) {
                                    f[r].maxApptNumber == -1 && (f[r].maxApptNumber = "");
                                    f[r].providerName = i[o].name;
                                    break
                                }
                        t.selectedChannelId == n.data[u].id && (t.apptItem = angular.copy(n.data[u]), e = !0)
                    }
                    e || (t.apptItem = angular.copy(n.data[0]), t.selectedChannelId = t.apptItem.id);
                    t.checkApptItemLength(t.apptItem);
                    t.apptItems = n;
                    t.apptItemsCache = angular.copy(n)
                })
            })
        },
        e = function(n) {
            t.isEdit = !1;
            f(n)
        },
        o = function(n, t) {
            r.updateApptItem(n).success(function() {
                u.success("保存成功");
                h(t)
            })
        },
        s = function(n) {
            r.updateItem(n).success(function() {
                e(n)
            }).error(function() {
                f(n)
            })
        },
        h = function(n) {
            e(n)
        };
    (function() {
        t.updateApptInventoryItem = o;
        t.updateItems = s
    })()
}]);
practiceModule.controller("ApptInventoryItemsSettingCtrl", ["$log", "$scope", "$timeout", "$q", "apptInventorySvc", "loginContext", "apptUtil", "aresDialog", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var c = function(i) {
            u.listTemplate(i).success(function(n) {
                t.apptInventoryTemplates = n
            }).error(function(t) {
                n.log(t);
                o.info("信息", "点评库存模板数据获取失败!")
            })
        },
        s = function(i) {
            var r = moment(t.range.start).format("YYYY-MM-DD"),
                f = moment(t.range.end).format("YYYY-MM-DD");
            u.listDailyInventory(i, r, f).success(function(n) {
                t.apptInventorys = n
            }).error(function(t) {
                n.log(t);
                o.info("信息", "点评库存数据获取失败!")
            })
        },
        h = function() {
            t.range = e.getDateRange(t.date, "w");
            t.range.monday = moment(t.range.start).format("YYYY-MM-DD");
            t.range.tuesday = moment(t.range.start).add(1, "d").format("YYYY-MM-DD");
            t.range.wednesday = moment(t.range.start).add(2, "d").format("YYYY-MM-DD");
            t.range.thursday = moment(t.range.start).add(3, "d").format("YYYY-MM-DD");
            t.range.friday = moment(t.range.start).add(4, "d").format("YYYY-MM-DD");
            t.range.saturday = moment(t.range.start).add(5, "d").format("YYYY-MM-DD");
            t.range.sunday = moment(t.range.start).add(6, "d").format("YYYY-MM-DD")
        },
        l = function(n, i) {
            t.date = moment(t.date).add(n, "d");
            h();
            s(i)
        },
        a = function(n, i) {
            t.isDayInventory !== n && (t.isDayInventory = n, t.isDayInventory ? s(i) : c(i))
        };
    (function() {
        t.date = Ares.today();
        t.isDayInventory = !0;
        t.changeWeek = l;
        t.getDateRange = h;
        t.initApptInventoryTemplates = c;
        t.initApptInventorys = s;
        t.toggleMode = a;
        h()
    })()
}]);
practiceModule.controller("ApptInventoyItemsSettingResetCtrl", ["$log", "$scope", "aresNotification", "$modalInstance", "apptInventorySvc", "host", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            u.updateTemplateAmountByChannelName(t.service, t.amount).success(function() {
                r.close(!0)
            }).error(function() {
                i.error("库存模板重置失败。")
            })
        },
        o = function() {
            r.dismiss("cancel")
        };
    (function() {
        t.service = f.service;
        t.cancel = o;
        t.confirm = e
    })()
}]);
practiceModule.controller("PracticeMessageBoxController", ["$scope", "$modalInstance", function(n, t) {
    "use strict";
    n.cancel = function() {
        t.dismiss("cancel")
    }
}]);
practiceModule.controller("PracticeDiagnosismBrowserCtrl", ["$log", "$scope", "$location", "$window", "$modal", "$http", "aresDialog", "appNav", "practiceSvc", "dataDicSvc", "loginContext", "$q", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    t.chargeCatagory = {};
    t.currentchargeitemcatagory = {};
    t.currentchargeitem = {};
    t.chargeitems = {};
    t.isAllCharge = !1;
    t.getDiscountString = function(n) {
        return n ? n.allowDiscount == null || n.allowDiscount == !0 ? "是" : "否" : "是"
    };
    t.browserDiagnoseItem = function() {
        var n = {
            pageSize: t.pageSize,
            pageIndex: t.pageIndex,
            diagnoseItemNameOrCode: t.searchString
        };
        s.getDiagnoseItemListByPage(n).success(function(n) {
            for (var i = 0; i < n.length; i++) n[i].index = i + 1, n[i].displayOrder = i;
            t.diagnoseItemList = n
        })
    };
    t.search = function() {
        var n = l.defer(),
            i = {
                pageSize: t.pageSize,
                pageIndex: t.pageIndex,
                diagnoseItemNameOrCode: t.searchString
            };
        return s.getDiagnoseItemListByPage(i).success(function(i) {
            for (var r = 0; r < i.items.length; r++) i.items[r].index = r + 1;
            t.diagnoseItemList = i.items;
            n.resolve(i)
        }), n.promise
    };
    t.isDisableDbClick = !1;
    var a = function(n, i) {
            var r, u, f, e;
            t.isDisableDbClick = !0;
            r = t.diagnoseItemList[i.index - 1];
            u = i.index - 1;
            t.diagnoseItemList.splice(i.index - 1, 1, t.diagnoseItemList[n.index - 1]);
            t.diagnoseItemList.splice(n.index - 1, 1, r);
            f = n.displayOrder;
            e = n.index;
            n.displayOrder = i.displayOrder;
            i.displayOrder = f;
            n.index = i.index;
            i.index = e;
            s.updateDiagnoseItemList(t.diagnoseItemList).success(function() {
                t.refreshUpDownGrid(u);
                t.isDisableDbClick = !1
            })
        },
        v = function(n, i) {
            var r, u, f, e;
            t.isDisableDbClick = !0;
            r = t.diagnoseItemList[n.index - 1];
            u = n.index - 1;
            t.diagnoseItemList.splice(n.index - 1, 1, t.diagnoseItemList[i.index - 1]);
            t.diagnoseItemList.splice(i.index - 1, 1, r);
            f = n.displayOrder;
            e = n.index;
            n.displayOrder = i.displayOrder;
            i.displayOrder = f;
            n.index = i.index;
            i.index = e;
            s.updateDiagnoseItemList(t.diagnoseItemList).success(function() {
                t.refreshDownGrid(u);
                t.isDisableDbClick = !1
            })
        },
        y = function() {
            var n = u.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-diagnosis-edit-view><\/practice-diagnosis-edit-view>",
                controller: "PracticeDiagnosisEditCtrl",
                size: "md",
                resolve: {
                    host: function() {
                        return {
                            diagnoseId: 0,
                            chargedisplayOrder: t.totalCount
                        }
                    }
                }
            });
            n.result.then(function() {
                t.relationGrid.dataSource.page(1);
                h.diagnoseItemDic.refresh()
            })
        },
        p = function(n) {
            if (n.isDefault) {
                t.showErrorNotification("基础项目不允许更改！");
                return
            }
            var i = u.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-diagnosis-edit-view><\/practice-diagnosis-edit-view>",
                controller: "PracticeDiagnosisEditCtrl",
                size: "md",
                resolve: {
                    host: function() {
                        return {
                            diagnoseId: n.id,
                            chargedisplayOrder: t.diagnoseItemList.length
                        }
                    }
                }
            });
            i.result.then(function() {
                t.refreshGrid();
                h.diagnoseItemDic.refresh()
            })
        },
        w = function(n) {
            if (n.isDefault) {
                t.showErrorNotification("基础项目不允许删除！");
                return
            }
            e.confirm("提示", "确定要删除此配置？").then(function() {
                s.deleteDiagnoseItem(n.id).success(function() {
                    t.showNotification("删除成功！");
                    t.initList();
                    h.diagnoseItemDic.refresh()
                })
            })
        };
    t.upItem = a;
    t.downItem = v;
    t.createDiagnoseItem = y;
    t.editDiagnoseItem = p;
    t.deleteDiagnoseItem = w
}]);
practiceModule.controller("PracticeDiagnosisEditCtrl", ["$log", "$scope", "$location", "$modalInstance", "$http", "$state", "aresDialog", "appNav", "practiceSvc", "dataDicSvc", "enums", "constants", "loginContext", "host", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    t.diagnoseItem = {};
    t.currentChargeItemCatagory = {};
    t.subChargeTypeList = {};
    t.cancel = function() {
        r.dismiss("cancel")
    };
    h.diagnoseItemDic.load();
    t.saveChargeItem = function() {
        var n = h.diagnoseItemDic.data();
        t.diagnoseItem.id ? s.updateDiagnoseItem(t.diagnoseItem).success(function(n) {
            t.showNotification("保存成功！");
            h.chargeItemDic.refresh();
            r.close(n)
        }).error(function() {}) : s.createDiagnoseItem(t.diagnoseItem).success(function(n) {
            t.showNotification("保存成功！");
            h.chargeItemDic.refresh();
            r.close(n)
        }).error(function() {})
    };
    var y = function() {
        jQuery.validator.addMethod("valItemCode", function(n) {
            var u = !0,
                r, i;
            if (n)
                for (r = h.diagnoseItemDic.data(), i = 0; i < r.length; ++i)
                    if (r[i].itemCode == n)
                        if (t.diagnoseItem.id == r[i].id) continue;
                        else {
                            u = !1;
                            return
                        }
            return u
        }, "编码已被使用！");
        jQuery.validator.addMethod("valItemName", function(n) {
            var u = !0,
                r, i;
            if (n)
                for (r = h.diagnoseItemDic.data(), i = 0; i < r.length; ++i)
                    if (r[i].itemName == n)
                        if (t.diagnoseItem.id == r[i].id) continue;
                        else {
                            u = !1;
                            return
                        }
            return u
        }, "名称已被使用！");
        jQuery.validator.addMethod("valItemEnName", function(n) {
            var u = !0,
                r, i;
            if (n)
                for (r = h.diagnoseItemDic.data(), i = 0; i < r.length; ++i)
                    if (r[i].itemEnName == n)
                        if (t.diagnoseItem.id == r[i].id) continue;
                        else {
                            u = !1;
                            return
                        }
            return u
        }, "英文名已被使用！")
    };
    y();
    t.catagoryId = v.catagoryId;
    t.diagnoseId = v.diagnoseId;
    t.displayOrder = v.chargedisplayOrder;
    t.diagnoseItem = t.diagnoseId > 0 ? h.diagnoseItemDic.getItemSync(t.diagnoseId) : {
        id: 0,
        itemName: "",
        itemCode: "",
        pinyin: "",
        itemEnName: "",
        isDefault: !1,
        displayOrder: t.displayOrder
    }
}]);
practiceModule.controller("PracticeEmrConfigCtrl", ["$log", "$scope", "officeSvc", "officeOptionSvc", "aresNotification", "aresDialog", "systemConfigUtil", "dataDicSvc", "$q", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var h = function(n) {
            t.activeType = n
        },
        c = function(n) {
            o.medicalRecordLayoutTemplateDic.load().then(function(i) {
                t.layoutTemplates = i;
                var r = {},
                    u = n ? n.split("|") : [];
                _.each(i, function(n) {
                    r[n.templateCode] = _(u).include(n.templateCode)
                });
                t.officeEmrSetings.emrConfig = r
            })
        },
        l = function() {
            var n = [];
            return _.each(t.layoutTemplates, function(i) {
                t.officeEmrSetings.emrConfig[i.templateCode] && n.push(i.templateCode)
            }), n.join("|")
        },
        a = function() {
            var n = [];
            return t.officeEmrSetings.firstEmrTemplateFields.chiefComplaint && n.push("chiefComplaint"), t.officeEmrSetings.firstEmrTemplateFields.history && n.push("history"), t.officeEmrSetings.firstEmrTemplateFields.pastHistory && n.push("pastHistory"), t.officeEmrSetings.firstEmrTemplateFields.advice && n.push("advice"), t.officeEmrSetings.firstEmrTemplateFields.cure && n.push("cure"), t.officeEmrSetings.firstEmrTemplateFields.diagnose && n.push("diagnose"), t.officeEmrSetings.firstEmrTemplateFields.oralCheck && n.push("oralCheck"), t.officeEmrSetings.firstEmrTemplateFields.radiologyCheck && n.push("radiologyCheck"), t.officeEmrSetings.firstEmrTemplateFields.associatedImage && n.push("associatedImage"), t.officeEmrSetings.firstEmrTemplateFields.treatmentPlan && n.push("treatmentPlan"), n.join("|")
        },
        v = function() {
            var n = [];
            return t.officeEmrSetings.secondEmrTemplateFields.chiefComplaint && n.push("chiefComplaint"), t.officeEmrSetings.secondEmrTemplateFields.history && n.push("history"), t.officeEmrSetings.secondEmrTemplateFields.pastHistory && n.push("pastHistory"), t.officeEmrSetings.secondEmrTemplateFields.advice && n.push("advice"), t.officeEmrSetings.secondEmrTemplateFields.cure && n.push("cure"), t.officeEmrSetings.secondEmrTemplateFields.diagnose && n.push("diagnose"), t.officeEmrSetings.secondEmrTemplateFields.oralCheck && n.push("oralCheck"), t.officeEmrSetings.secondEmrTemplateFields.radiologyCheck && n.push("radiologyCheck"), t.officeEmrSetings.secondEmrTemplateFields.associatedImage && n.push("associatedImage"), t.officeEmrSetings.secondEmrTemplateFields.treatmentPlan && n.push("treatmentPlan"), n.join("|")
        },
        y = function() {
            var r = [],
                n = "EMRTimeLimit",
                i = t.systemConfigs.emrTimeLimitValue;
            return r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "IsDisableEMRTimeLimit", i = t.systemConfigs.isDisableEMRTimeLimitValue ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "IsDisableEMRBlankPrint", i = t.systemConfigs.isDisableEMRBlankPrint ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "IsEnableEMRLittleToothPrint", i = t.systemConfigs.isEnableEMRLittleToothPrint ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "AllowToothFDI", i = t.systemConfigs.allowToothFDI ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "AllowEditToothFDI", i = t.systemConfigs.allowEditToothFDI ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "EMRWritingLimit", i = t.systemConfigs.emrWritingLimitValue, r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "IsEnableEMRWritingLimit", i = t.systemConfigs.isEnableEMRWritingLimitValue ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR"
            }), n = "IsAloneSaveOralCheckSymptom", i = t.systemConfigs.isAloneSaveOralCheckSymptom ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR",
                Coments: "口腔检查症状单独保存"
            }), n = "IsPrintAllEmrAsc", i = t.systemConfigs.isPrintAllEmrAsc ? "true" : "false", r.push({
                configName: n,
                configValue: i,
                configType: "EMR",
                Coments: "按时间升序打印全部病例"
            }), r
        },
        p = function() {
            var s = l(),
                n = a(),
                o = v(),
                p = y(),
                h = {
                    emrCategory: s,
                    firstEmrTemplateFields: n,
                    secondEmrTemplateFields: o,
                    isMedicalRecordPaginationPrintEnabled: t.officeEmrSetings.isMedicalRecordPaginationPrintEnabled,
                    systemConfigs: p
                },
                w = t.officeEmrSetings.isMedicalRecordPaginationPrintEnabled,
                c;
            if (t.officeEmrSetings.emrConfig.firstEmr && n == "") {
                f.info("信息", "请选择初诊病历模板字段!");
                return
            }
            if (t.officeEmrSetings.emrConfig.secondEmr && o == "") {
                f.info("信息", "请选择复诊病历模板字段!");
                return
            }
            i.updateOfficeEmrSetting(h).success(function(i) {
                i ? (r.refreshOfficeOption(r.optionKeys.EmrCategory, s), r.refreshOfficeOption(r.optionKeys.FirstEmrTemplateFields, n), r.refreshOfficeOption(r.optionKeys.SecondEmrTemplateFields, o), r.refreshOfficeOption(r.optionKeys.IsMedicalRecordPaginationPrintEnabled, w), e.refreshCache(h.systemConfigs), u.success("保存成功"), t.isEdit = !t.isEdit) : u.error("保存失败")
            });
            c = {
                isByApptTimeAsc: t.officeEmrSetings.MedicalRecordPrintConfig.isByApptTimeAsc
            };
            r.setOfficeOption("MedicalRecordPrintConfig", c).then(function() {})
        },
        w = function(n) {
            if (n) {
                var n = n.split("|"),
                    i = _.indexOf(n, "chiefComplaint") > -1,
                    r = _.indexOf(n, "history") > -1,
                    u = _.indexOf(n, "pastHistory") > -1,
                    f = _.indexOf(n, "oralCheck") > -1,
                    e = _.indexOf(n, "radiologyCheck") > -1,
                    o = _.indexOf(n, "associatedImage") > -1,
                    s = _.indexOf(n, "treatmentPlan") > -1,
                    h = _.indexOf(n, "diagnose") > -1,
                    c = _.indexOf(n, "cure") > -1,
                    l = _.indexOf(n, "advice") > -1,
                    a = {
                        chiefComplaint: i,
                        history: r,
                        pastHistory: u,
                        oralCheck: f,
                        radiologyCheck: e,
                        associatedImage: o,
                        treatmentPlan: s,
                        diagnose: h,
                        cure: c,
                        advice: l
                    };
                t.officeEmrSetings.firstEmrTemplateFields = a
            }
        },
        b = function(n) {
            if (n) {
                var n = n.split("|"),
                    i = _.indexOf(n, "chiefComplaint") > -1,
                    r = _.indexOf(n, "history") > -1,
                    u = _.indexOf(n, "pastHistory") > -1,
                    f = _.indexOf(n, "oralCheck") > -1,
                    e = _.indexOf(n, "radiologyCheck") > -1,
                    o = _.indexOf(n, "associatedImage") > -1,
                    s = _.indexOf(n, "treatmentPlan") > -1,
                    h = _.indexOf(n, "diagnose") > -1,
                    c = _.indexOf(n, "cure") > -1,
                    l = _.indexOf(n, "advice") > -1,
                    a = {
                        history: r,
                        pastHistory: u,
                        chiefComplaint: i,
                        oralCheck: f,
                        radiologyCheck: e,
                        associatedImage: o,
                        treatmentPlan: s,
                        diagnose: h,
                        cure: c,
                        advice: l
                    };
                t.officeEmrSetings.secondEmrTemplateFields = a
            }
        },
        k = function() {
            i.getOfficeEmrSetting().success(function(n) {
                t.officeEmrSetings = n;
                t.systemConfigs = {};
                c(t.officeEmrSetings.emrCategory);
                w(t.officeEmrSetings.firstEmrTemplateFields);
                b(t.officeEmrSetings.secondEmrTemplateFields);
                angular.forEach(t.officeEmrSetings.systemConfigs, function(n) {
                    n.configName == "IsDisableEMRTimeLimit" ? t.systemConfigs.isDisableEMRTimeLimitValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "EMRTimeLimit" ? t.systemConfigs.emrTimeLimitValue = n.configValue : n.configName == "IsDisableEMRBlankPrint" ? t.systemConfigs.isDisableEMRBlankPrint = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowToothFDI" ? t.systemConfigs.allowToothFDI = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "AllowEditToothFDI" ? t.systemConfigs.allowEditToothFDI = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "IsEnableEMRLittleToothPrint" ? t.systemConfigs.isEnableEMRLittleToothPrint = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "IsEnableEMRWritingLimit" ? t.systemConfigs.isEnableEMRWritingLimitValue = n.configValue.toUpperCase() == "TRUE" ? !0 : !1 : n.configName == "EMRWritingLimit" ? t.systemConfigs.emrWritingLimitValue = n.configValue : n.configName == "IsAloneSaveOralCheckSymptom" && (t.systemConfigs.isAloneSaveOralCheckSymptom = n.configValue.toUpperCase() == "TRUE" ? !0 : !1)
                });
                d()
            })
        },
        d = function() {
            var n = s.defer();
            return r.getOfficeOption(["MedicalRecordPrintConfig"]).then(function(i) {
                i ? (t.officeEmrSetings.MedicalRecordPrintConfig = typeof i != "object" || Object.prototype.toString.call(i).toLowerCase() != "[object object]" || i.length ? JSON.parse(i) : i, t.officeEmrSetings.MedicalRecordPrintConfig.isByApptTimeAsc = t.officeEmrSetings.MedicalRecordPrintConfig.IsByApptTimeAsc || t.officeEmrSetings.MedicalRecordPrintConfig.isByApptTimeAsc) : t.officeEmrSetings.MedicalRecordPrintConfig = {
                    isByApptTimeAsc: !1
                };
                n.resolve(!0)
            }), n.promise
        };
    (function() {
        t.isEdit = !1;
        t.officeEmrSetings = null;
        t.selectType = h;
        t.activeType = 1;
        t.saveEmrSettings = p;
        k()
    })()
}]);
practiceModule.controller("PracticeEmrtemplateBrowserCreateItemCtrl", ["$log", "$scope", "$modalInstance", "host", "enums", function(n, t, i, r, u) {
    "use strict";
    var h = function() {
            i.dismiss("cancel")
        },
        e = r.type,
        f = r.itemData,
        o, s;
    switch (e) {
        case 1:
            t.title = "修改目录名称";
            t.newDiseaseItem = angular.copy(f);
            break;
        case 2:
            t.title = "新增目录";
            t.newDiseaseItem = {
                itemName: "",
                parentId: f.id,
                pinyin: "",
                ownerId: null
            };
            break;
        case 3:
            t.title = "新增模板";
            t.newEMRTemplate = {
                templateName: "",
                Pinyin: "",
                diseaseId: f.id,
                diseaseName: f.itemName,
                chiefComplaint: "",
                history: "",
                pastHistory: "",
                oralCheck: "",
                otherCheck: "",
                diagnose: "",
                treatmentAdvice: "",
                treatmentPlan: "",
                treatment: "",
                advice: "",
                userId: null,
                templateType: u.TemplateType.Default
            };
            t.isEmrCustomTemplateEnabled = r.isEmrCustomTemplateEnabled
    }
    o = function() {
        i.close(t.newDiseaseItem)
    };
    s = function() {
            i.close(t.newEMRTemplate)
        },
        function() {
            t.cancel = h;
            t.showType = e;
            t.itemData = f;
            t.parentNode = r.parentNode;
            t.saveDiseaseItem = o;
            t.saveEmrTemplate = s
        }()
}]);
practiceModule.controller("PracticeEmrtemplateBrowserDirectoryMoveCtrl", ["$log", "$scope", "$http", "$state", "$modalInstance", "aresDialog", "patientSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    t.cancel = function() {
        u.dismiss("cancel")
    };
    var h = o.currentEmrTemplate,
        s = o.treeControl,
        c = s.getTree(),
        l = o.templateType,
        a = o.templateCode,
        v = o.diseaseItemName,
        y = function(n) {
            e.moveEMRTemplate(n).success(function(n) {
                u.close(n)
            })
        },
        p = {
            showActionBar: !1,
            showLeafs: !1
        };
    (function() {
        t.currentEmrTemplate = h;
        t.treeControl = s;
        t.treeData = c;
        t.treeOpts = p;
        t.templateType = l;
        t.templateCode = a;
        t.diseaseItemName = v;
        t.moveTemplate = y
    })()
}]);
practiceModule.controller("PracticeEmrtemplateCtrl", ["$log", "$scope", "$location", "$http", "$q", "$modal", "appNav", "aresNotification", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "officeOptionSvc", "officeUtil", "aresTreeControlUtil", "emrUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b) {
    "use strict";
    var nt = function(n, i) {
            (t.templateTreeControl = new w.TreeControl(n, i), t.templateTreeControl) && (t.treeData = t.templateTreeControl.getTree())
        },
        tt = function(n) {
            t.expandedNodes = [];
            h.listDiseaseItems(l.DiseaseType.Default).success(function(i) {
                var r = b.getTemplateTypeByCode(n);
                h.listEMRTemplates(r, n).success(function(n) {
                    t.constructEMRTemplateTreeData(i, n)
                })
            })
        },
        it = function() {
            if (!k()) return !1;
            t.savedEmrTemplate = angular.copy(t.currentEmrTemplate);
            t.isEditEmrTemplate = !0
        },
        rt = function() {
            if (!k()) return !1;
            h.updateEMRTemplate(t.currentEmrTemplate).success(function(n) {
                o.success("保存成功");
                t.templateTreeControl.updateLeaf(n)
            }).error(function(t) {
                n.debug(t)
            });
            t.isEditEmrTemplate = !1
        },
        ut = function() {
            if (!k()) return !1;
            t.currentEmrTemplate = angular.copy(t.savedEmrTemplate);
            t.isEditEmrTemplate = !1
        },
        ft = function() {
            var n = u.defer();
            return y.getOfficeOption(y.optionKeys.IsEmrCustomTemplateEnabled).then(function(i) {
                i && (t.isEmrCustomTemplateEnabled = !0);
                n.resolve(!0)
            }), n.promise
        },
        et = function() {
            var n = u.defer();
            return p.isParentEnabled("EMR").then(function(i) {
                t.isEMRParentEnabled = i;
                n.resolve(!0)
            }), n.promise
        },
        k = function() {
            return !d(t.selectedNode) && t.isTemplateParentEnabled ? (o.error("使用总部配置，不能编辑"), !1) : !0
        },
        d = function(n) {
            var i = t.treeData[0];
            return g(i, n.id)
        },
        g = function(n, t) {
            if (n.id == t) return !0;
            var i = n.childrenItems,
                r = !1;
            return i && _(i).each(function(n) {
                g(n, t) && (r = !0)
            }), r
        },
        ot = function(n) {
            if (!k()) return !1;
            var i = f.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-emrtemplate-browser-directory-move-view><\/practice-emrtemplate-browser-directory-move-view>",
                controller: "PracticeEmrtemplateBrowserDirectoryMoveCtrl",
                windowClass: "practice-emrtemplate-browser-directory-move",
                resolve: {
                    host: function() {
                        return {
                            currentEmrTemplate: n,
                            treeControl: t.templateTreeControl,
                            layoutTemplateCode: t.layoutTemplateCode,
                            templateType: b.getTemplateTypeByCode(t.layoutTemplateCode),
                            diseaseItemName: t.diseaseItemName
                        }
                    }
                }
            });
            i.result.then(function(n) {
                t.selectedNode = {};
                t.currentEmrTemplate = {};
                t.templateTreeControl.moveLeaf(n)
            })
        },
        st = function() {
            var n = u.defer();
            return c.medicalRecordLayoutTemplateDic.load().then(function(i) {
                t.layoutTemplates = i;
                n.resolve()
            }), n.promise
        },
        ht = function() {
            var n = l.BaseDataCategory,
                i = n.EMR;
            c.officeBaseDataOptionDic.load().then(function(n) {
                var r = _.find(n, function(n) {
                    return n.category == i
                });
                t.isTemplateParentEnabled = r && r.isParentEnabled ? !0 : !1
            })
        };
    (function() {
        t.currentEmrTemplate = {};
        t.backupEmrTemplate = {};
        t.isEditEmrTemplate = !1;
        t.opts = {
            dirSelectable: !1
        };
        t.currentDiseaseItem = null;
        t.initEHRParentEnabled = et;
        t.initOfficeOption = ft;
        t.constructEMRTemplateTreeData = nt;
        t.cancelEmrTemplate = ut;
        t.saveEmrTemplate = rt;
        t.editEmrTemplate = it;
        t.browserEMRTemplateSetting = tt;
        t.moveEmrTemplate = ot;
        t.isMyTemplateNodeChild = d;
        st();
        ht()
    })()
}]);
practiceModule.controller("PracticeEmrtemplateItemMainTypeCtrl", ["$log", "$scope", "$location", "$http", "$modalInstance", "aresDialog", "$state", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "aresNotification", "host", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    t.mainType = angular.copy(p.mainType);
    t.mainType.itemName.indexOf("病历词条-") >= 0 && (t.mainType.itemName = t.mainType.itemName.replace("病历词条-", ""));
    t.isEdit = p.isEdit;
    t.cancel = function() {
        u.dismiss("cancel")
    };
    t.saveEmrTemplateItemMainType = function() {
        t.mainType.itemName.indexOf("病历词条-") == -1 && (t.mainType.itemName = "病历词条-" + t.mainType.itemName);
        s.createOrUpdateEmrTemplateItemMainType(t.mainType).success(function(n) {
            y.success("保存成功！");
            u.close(n)
        }).error(function(n) {
            n.name == "SystemSettingItemNameNotUniqueException" && f.warn("警告", "已经有大类使用此名称，请更换新名称！")
        })
    }
}]);
practiceModule.controller("PracticeEmrtemplateItemsettingCategoryCtrl", ["$log", "$scope", "$location", "$http", "$modalInstance", "aresDialog", "$state", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "aresNotification", "host", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    t.mainType = p;
    t.cancel = function() {
        u.dismiss("cancel")
    };
    t.saveEmrtemplageItemSetting = function() {
        h.updateEMRTemplateItemSubType(t.mainType).success(function(n) {
            y.success("保存成功！");
            u.close(n)
        }).error(function(n) {
            n.name == "SystemSettingItemNameNotUniqueException" && f.warn("警告", "已经有类目使用此名称，请更换新名称！")
        })
    }
}]);
practiceModule.controller("PracticeEmrtemplateItemSettingCtrl", ["$log", "$scope", "$location", "$http", "$q", "$modal", "appNav", "aresNotification", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "officeOptionSvc", "officeUtil", "aresDialog", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w) {
    "use strict";
    var b = function() {
            c.emrTemplateItemMainTypeDic.load().then(function(n) {
                t.emrTemplateItemSettingMainTypes = n;
                t.mainType = t.emrTemplateItemSettingMainTypes[0];
                t.subTypesMap = {
                    mainType: t.mainType.itemName,
                    subTypes: []
                };
                k()
            })
        },
        k = function() {
            h.listEMRTemplateTreeItems().success(function(n) {
                t.emrTemplateItemSettingData = n;
                n.length > 0 && (angular.forEach(n, function(n) {
                    n.mainType == t.mainType.itemName && (t.subTypesMap = n)
                }), t.subTypesMap.subTypes.length > 0 && (t.subItems = t.subTypesMap.subTypes[t.showItemIndex]))
            })
        },
        d = function(n, i) {
            h.deleteEMRTemplateItemSubType(n).success(function() {
                t.subTypesMap.subTypes.splice(i, 1);
                o.success("删除成功！")
            }).error(function() {
                w.warn("信息", "删除失败")
            })
        },
        g = function(n) {
            var i = {},
                r = [],
                u;
            angular.forEach(n, function(n) {
                i.subTypeId = n.subTypeId;
                i.subType = n.subType;
                i.subTypeOrder = n.subTypeOrder;
                u = n.mainType;
                var t = {
                    id: n.id,
                    itemCode: n.itemCode,
                    itemName: n.itemContent,
                    itemContent: n.itemContent,
                    order: n.order
                };
                r.push(t)
            });
            i.items = r;
            t.subItems = i;
            angular.forEach(t.emrTemplateItemSettingData, function(n) {
                n.mainType == u && angular.forEach(n.subTypes, function(n) {
                    n.subTypeId == t.subItems.subTypeId && (n.items = t.subItems.items)
                })
            })
        },
        nt = function(n) {
            var r, i;
            r = t.emrTemplateItemSettingData.length === 0 ? [t.subTypesMap] : t.emrTemplateItemSettingData;
            i = [];
            angular.forEach(r, function(t) {
                var r = t.mainType;
                angular.forEach(t.subTypes, function(t) {
                    var f = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder
                        },
                        u;
                    t.subTypeId == n && t.items.length > 0 ? angular.forEach(t.items, function(n, u) {
                        var f = {
                            subTypeId: t.subTypeId,
                            subType: t.subType,
                            subTypeOrder: t.subTypeOrder,
                            id: n.id ? n.id : 0,
                            itemCode: "",
                            itemName: n.itemContent,
                            itemContent: n.itemContent,
                            order: u,
                            mainType: r
                        };
                        i.push(f)
                    }) : t.subTypeId == n && t.items.length === 0 && (u = {
                        subTypeId: t.subTypeId,
                        subType: t.subType,
                        subTypeOrder: t.subTypeOrder,
                        id: 0,
                        itemCode: "",
                        itemName: "",
                        itemContent: "",
                        order: "",
                        mainType: r
                    }, i.push(u))
                })
            });
            i = JSON.stringify(i);
            h.updateEMRTemplateItem(i).success(function(n) {
                g(n);
                t.isEdit = !1;
                o.success("保存成功！")
            }).error(function() {
                w.warn("信息", "保存失败")
            })
        };
    (function() {
        t.deleteSubTypeItem = d;
        t.saveEmrItemContent = nt;
        t.showSubTypeIndex = 0;
        t.showItemIndex = 0;
        t.subItems = {
            items: []
        };
        b()
    })()
}]);
practiceModule.controller("PracticeOperatoryBrowserCtrl", ["$log", "$timeout", "$scope", "$modal", "practiceSvc", "dataDicSvc", "aresDialog", "operatorySvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s, h;
    i.operators = [];
    i.browserOpratorySetting = function() {
        u.listAllOperatoryProvider().success(function(n) {
            var r, t, u;
            for (i.operators = n, r = 0; r < i.operators.length; r++) t = i.operators[r], t.showOrder == 0 && (t.showOrder = r + 1), t.providerNameStr = "", t.providers && t.providers.length > 0 && (u = _.map(t.providers, function(n) {
                return n.name
            }), t.providerNameStr = u.join(","))
        }).error(function() {
            i.operators = {};
            alert("无法获取诊室信息！")
        })
    };
    i.createOperatory = function() {
        var n = r.open({
            animation: !0,
            backdrop: "static",
            template: "<practice-operatory-edit-view><\/practice-operatory-edit-view>",
            controller: "PracticeOperatoryEditCtrl",
            windowClass: "image-appointments-select-dialog",
            resolve: {
                host: function() {
                    return {
                        operatoryId: 0
                    }
                }
            }
        });
        n.result.then(function() {
            i.browserOpratorySetting()
        })
    };
    i.editOperatory = function(n) {
        var t = r.open({
            animation: !0,
            backdrop: "static",
            template: "<practice-operatory-edit-view><\/practice-operatory-edit-view>",
            controller: "PracticeOperatoryEditCtrl",
            windowClass: "image-appointments-select-dialog",
            resolve: {
                host: function() {
                    return {
                        operatoryId: n
                    }
                }
            }
        });
        t.result.then(function() {
            i.browserOpratorySetting();
            f.operatoryDic.refresh()
        })
    };
    i.deleteOperator = function(n) {
        e.confirm("提示", "确定要删除此配置？").then(function() {
            n && u.deleteOperator(n).success(function() {
                i.browserOpratorySetting();
                f.operatoryDic.refresh()
            }).error(function(n) {
                alert(n);
                i.data.error = n;
                i.browserOpratorySetting()
            })
        })
    };
    i.move = function(n) {
        var t, r, f, u, e, s;
        if (i.selectedItem && (t = i.operators, r = _.findIndex(t, {
                id: i.selectedItem.id
            }), r > -1)) {
            if (f = t[r], u = r + n, u < 0 || u >= t.length) return;
            e = t[u];
            s = f.showOrder;
            f.showOrder = e.showOrder;
            e.showOrder = s;
            o.updateShowOrder(i.selectedItem.id, n).success(function(n) {
                n && i.browserOpratorySetting();
                i.operators = _.sortBy(i.operators, "showOrder");
                h()
            })
        }
    };
    h = function() {
        s && t.cancel(s);
        s = t(function() {
            f.operatoryDic.refresh()
        }, 2e3)
    };
    i.browserOpratorySetting();
    i.$on("$destroy", function() {
        s && t.cancel(s);
        f.operatoryDic.refresh()
    })
}]);
practiceModule.controller("PracticeOperatoryEditCtrl", ["$log", "$scope", "$modalInstance", "practiceSvc", "dataDicSvc", "loginContext", "host", "operatorySvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    t.currentOperator = {};
    t.cancel = function() {
        t.currentOperator = {};
        i.dismiss("cancel")
    };
    t.saveOperator = function() {
        t.currentOperator.id ? r.updateOperator(t.currentOperator).success(function(n) {
            u.operatoryDic.refresh();
            i.close(n)
        }).error(function() {}) : r.createOperator(t.currentOperator).success(function(n) {
            u.operatoryDic.refresh();
            i.close(n)
        }).error(function() {})
    };
    t.operatoryId = e.operatoryId;
    t.operatoryId > 0 ? o.getProviders(t.operatoryId).success(function(n) {
        t.currentOperator = u.operatoryDic.getItemSync(t.operatoryId);
        t.currentOperator.providers = n;
        t.isInitDoctor = !0
    }) : (t.currentOperator = {
        id: 0,
        name: "",
        description: "",
        officeId: f.officeId,
        providers: null
    }, t.isInitDoctor = !0)
}]);
practiceModule.controller("PracticeSystemconfigBrowserCtrl", ["$log", "$scope", "$location", "$http", "aresDialog", "appNav", "practiceSvc", "dataDicSvc", "loginContext", function(n, t, i, r, u, f, e) {
    "use strict";
    t.createSchedulerule = function() {
        f.switchState("setting.scheduleruleEdit", {
            ruleId: 0
        })
    };
    t.initScheduleList = function() {
        t.scheduleruleList = {};
        e.listScheduleRules().success(function(n) {
            for (var i = 0; i < n.length; ++i) n[i].startDatestr = moment(n[i].startDate).format("YYYY-MM-DD"), n[i].endDatestr = moment(n[i].endDate).format("YYYY-MM-DD"), n[i].isRunningStr = n[i].isRunning == !1 ? "否" : "是";
            t.scheduleruleList = n
        })
    };
    t.initScheduleList()
}]);
practiceModule.controller("PracticeSystemsettingApptTypeEditCtrl", ["$log", "$scope", "$modalInstance", "host", "$modal", "practiceSvc", "aresDialog", "transactionCodeSvc", "dataDicSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var h = function(n, t) {
            this.name = n;
            this.value = t
        },
        l = [new h("粉色10", "#ffb2ef"), new h("紫色10", "#e4b9ff"), new h("靛蓝10", "#b9caff"), new h("水绿10", "#a3f4e8"), new h("绿色10", "#a5f6b9"), new h("绿黄10", "#e2f6a5"), new h("黄色10", "#ffe8aa"), new h("橙色10", "#ffd1aa"), new h("红色10", "#ffb9be"), new h("无", "#ffffff"), ],
        c = _.map(l, function(n) {
            return n.value
        }),
        v = function() {
            c.length = l.length;
            angular.forEach(t.systemsetings, function(n) {
                var t = n.itemValue;
                (t == "#ffffff" || t == "#FFFFFF" || t == "transparent") && (t = null);
                t && c.indexOf(t) < 0 && c.push(t)
            })
        },
        y = function() {
            r.systemsetting ? (t.systemseting = r.systemsetting, t.oldItemName = r.systemsetting.itemName) : t.systemseting = {
                itemName: "",
                itemValue: null,
                itemType: "预约大类",
                isInactive: !1,
                isDefault: !1,
                displayOrder: _.max(t.systemsetings, function(n) {
                    return n.displayOrder
                }).displayOrder + 1e3
            };
            v()
        },
        p = function() {
            t.systemseting.id > 0 ? t.systemseting.isInactive ? o.hasCategory(t.systemseting.itemName).success(function(n) {
                n ? e.info("提示", "该预约大类下已存在预约项目，不允许禁用!") : a()
            }) : a() : f.createSystemSettingItem(t.systemseting).success(function(n) {
                n && i.close(t.systemseting)
            }).error(function(n) {
                n.name === "SystemSettingItemNameNotUniqueException" && e.warn("提示", "该名称已经存在！")
            })
        },
        a = function() {
            f.updateSystemSettingItem(t.systemseting).success(function(n) {
                n && o.updateCategory(t.oldItemName, t.systemseting.itemName).success(function() {
                    s.systemsettingDic.refresh().then(function() {
                        s.transactionCodeDic.refresh().then(function() {
                            i.close(n)
                        })
                    })
                })
            }).error(function(n) {
                n.name === "SystemSettingItemNameNotUniqueException" && e.warn("提示", "该名称已经存在！")
            })
        },
        w = function() {
            i.close()
        };
    (function() {
        t.systemsetings = r.systemsettings;
        t.procedureColors = l;
        t.colorValues = c;
        t.cancel = w;
        t.save = p;
        y()
    })()
}]);
practiceModule.controller("PracticeSystemsettingApptTypeCtrl", ["$log", "$timeout", "$scope", "$modal", "aresDialog", "aresNotification", "practiceSvc", "transactionCodeSvc", "dataDicSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var h, c = function() {
            e.GetTransactionCodeCategorylist(i.showIsEableOrAll).success(function(n) {
                n && (angular.forEach(n, function(n, t) {
                    n.displayOrder = t + 1;
                    n.isDefaultStr = n.isDefault ? "系统" : "自定义";
                    n.isInactiveStr = n.isInactive ? "禁用" : "启用"
                }), i.systemsettings = n)
            })
        },
        y = function(n) {
            n.isInactive ? a(n) : o.hasCategory(n.itemName).success(function(t) {
                t ? u.info("提示", "该预约大类下已存在预约项目，不允许禁用!") : a(n)
            })
        },
        a = function(n) {
            n.isInactive = !n.isInactive;
            var t = n.isInactive ? "禁用" : "启用";
            e.updateSystemSettingItem(n).success(function(n) {
                n && (c(), f.success(t + "成功！"))
            }).error(function(n) {
                n.name === "SystemSettingItemNameNotUniqueException" && u.warn("提示", "该名称已经存在！")
            })
        },
        p = function(n) {
            var t, u;
            n && (t = angular.copy(n));
            u = r.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-systemsetting-appt-type-edit-view><\/practice-systemsetting-appt-type-edit-view>",
                controller: "PracticeSystemsettingApptTypeEditCtrl",
                windowClass: "image-appointments-select-dialog",
                resolve: {
                    host: function() {
                        return {
                            systemsettings: i.systemsettings,
                            systemsetting: t
                        }
                    }
                }
            });
            u.result.then(function(n) {
                n && s.systemsettingDic.refresh().then(function() {
                    c()
                })
            })
        },
        w = function(n) {
            o.hasCategory(n.itemName).success(function(t) {
                t ? u.confirm("提示", "该预约大类下已存在预约项目，如确认删除该大类，相关预约项目将被默认关联到 “其他”分类！").then(function() {
                    v(n.id)
                }) : u.confirm("提示", "您确认要删除吗？").then(function() {
                    v(n.id)
                })
            })
        },
        v = function(n) {
            e.destroySystemSettingItem(n).success(function(n) {
                n && s.systemsettingDic.refresh().then(function() {
                    c();
                    s.transactionCodeDic.refresh()
                })
            })
        },
        b = function(n, t) {
            var r = n.displayOrder,
                u, f;
            n.displayOrder = t.displayOrder;
            t.displayOrder = r;
            u = _.find(i.systemsettings, function(t) {
                return t.id == n.id
            });
            u.displayOrder = n.displayOrder;
            f = _.find(i.systemsettings, function(n) {
                return n.id == t.id
            });
            f.displayOrder = t.displayOrder;
            i.systemsettings.splice(r - 1, 1, f);
            i.systemsettings.splice(r - 2, 1, u);
            i.refreshUpDownGrid(r);
            l()
        },
        k = function(n, t) {
            var r = n.displayOrder,
                u, f;
            n.displayOrder = t.displayOrder;
            t.displayOrder = r;
            u = _.find(i.systemsettings, function(t) {
                return t.id == n.id
            });
            u.displayOrder = n.displayOrder;
            f = _.find(i.systemsettings, function(n) {
                return n.id == t.id
            });
            f.displayOrder = t.displayOrder;
            i.systemsettings.splice(r - 1, 1, f);
            i.systemsettings.splice(r, 1, u);
            i.refreshDownGrid(r);
            l()
        },
        l = function() {
            h && t.cancel(h);
            h = t(function() {
                e.updateSystemSettingItemList(i.systemsettings).success(function() {
                    s.systemsettingDic.refresh()
                })
            }, 1e3)
        };
    (function() {
        i.showIsEableOrAll = !1;
        i.upItem = b;
        i.downItem = k;
        i.openEditDialog = p;
        i.isEnable = y;
        i.deleteSystemSetting = w;
        i.$watch("showIsEableOrAll", function() {
            l();
            c()
        });
        i.$on("$destroy", function() {
            h && t.cancel(h);
            e.updateSystemSettingItemList(i.systemsettings).success(function() {
                s.systemsettingDic.refresh()
            })
        })
    })()
}]);
practiceModule.controller("PracticeSystemSettingBrowserCtrl", ["$log", "$scope", "$location", "$http", "$modal", "aresDialog", "appNav", "practiceSvc", "dataDicSvc", "loginContext", "permissionProvider", "constants", "moduleOptionProvider", "systemConfigUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v) {
    "use strict";
    var p, y;
    t.systemSettingItems = {};
    t.currentParentSettingItem = {};
    t.browserSystemItemSetting = function(n) {
        n ? s.systemsettingDic.load().then(function(i) {
            t.systemSettingItems = i;
            var r = t.getTopLevelSettingItems(t.systemSettingItems);
            r = r.filter(function() {
                return n.itemKey != "收费项目" && n.itemKey != "收费方式" && n.itemKey != "费用类型"
            });
            a.isNewInventoryOpen() && r && (r = _.filter(r, function(n) {
                return !(n.itemName == "库存物品类别" || n.itemName == "物品供应商" || n.itemName == "出库领用类型")
            }));
            t.systemSettingItemTreeData = new kendo.data.HierarchicalDataSource({
                data: r
            });
            !n.itemType && n.key && t.currentParentSettingItem != n && (t.currentParentSettingItem = _.find(t.systemSettingTopLevel, {
                itemKey: n.key
            }));
            t.onSystemSettingParentItemChange(t.currentParentSettingItem);
            t.systemsettingList = t.getChildrenSystemSettingItems(t.currentParentSettingItem)
        }) : s.systemsettingDic.load().then(function(n) {
            t.systemSettingItems = n;
            var i = t.getTopLevelSettingItems(t.systemSettingItems);
            i = i.filter(function(n) {
                return n.itemKey != "收费项目" && n.itemKey != "收费方式" && n.itemKey != "费用类型"
            });
            a.isNewInventoryOpen() && i && (i = _.filter(i, function(n) {
                return !(n.itemName == "库存物品类别" || n.itemName == "物品供应商" || n.itemName == "出库领用类型")
            }));
            t.systemSettingItemTreeData = new kendo.data.HierarchicalDataSource({
                data: i
            });
            t.onSystemSettingParentItemChange(t.systemSettingTopLevel[0]);
            t.systemsettingList = t.getChildrenSystemSettingItems(t.currentParentSettingItem)
        })
    };
    p = function(n) {
        var i = _.include(["费用类型"], n),
            r = _.include(["患者类型", "系统疾病史", "现用药情况", "药物过敏", "手机号码属性", "电话号码属性", "关系类别"], n),
            u = _.include([], n),//["咨询项目", "就诊类型"]
            f = _.include(["科室"], n),
            e = _.include(["线索追踪"], n),
            o = !i && !r && !u && !f && !e;
        t.settingTypeInfo = {
            isChargeItemSetting: i,
            isPatientInfoSetting: r,
            isAppointmentSetting: u,
            isDepartmentSetting: f,
            isOtherSetting: o,
            isCustomerClueSetting: e
        }
    };
    t.onSystemSettingParentItemChange = function(n) {
        console.log(n);
        t.currentParentSettingItem = n;
        p(n.itemName);
        t.systemsettingList = t.getChildrenSystemSettingItems(t.currentParentSettingItem);
        t.settingTypeInfo.isCustomerClueSetting ? t.systemSettingGrid && t.systemSettingGrid.showColumn("itemValue") : t.systemSettingGrid && t.systemSettingGrid.hideColumn("itemValue");
        t.settingTypeInfo.isDepartmentSetting ? t.systemSettingGrid && t.systemSettingGrid.showColumn("itemCode") : t.systemSettingGrid && t.systemSettingGrid.hideColumn("itemCode")
    };
    t.isHideButton = function(n, t) {
        if (n.itemType == "收费项目") {
            var i = t,
                r = c.isAllowed(i);
            return r ? !1 : !0
        }
        return !1
    };
    t.createSystemSettingItem = function() {
        for (var i, n = 0; n < t.itemTypeList.length; ++n)
            if (t.itemTypeList[n].key == t.currentParentSettingItem.itemKey) {
                i = u.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-systemsetting-edit-view><\/practice-systemsetting-edit-view>",
                    controller: "PracticeSystemSettingEditCtrl",
                    size: "sm",
                    resolve: {
                        host: function() {
                            return {
                                systemsettingId: 0,
                                parentCatagoryId: n,
                                displayOrder: t.systemsettingList.length,
                                settingTypeInfo: t.settingTypeInfo
                            }
                        }
                    }
                });
                i.result.then(function(n) {
                    s.systemsettingDic.clearCache();
                    s.clearSystemSettingCache(n.itemType);
                    t.browserSystemItemSetting(n)
                });
                break
            }
    };
    y = function(n) {
        var i = u.open({
            animation: !0,
            backdrop: "static",
            template: "<practice-systemsetting-edit-view><\/practice-systemsetting-edit-view>",
            controller: "PracticeSystemSettingEditCtrl",
            size: "sm",
            resolve: {
                host: function() {
                    return {
                        systemsettingId: n.id,
                        parentCatagoryId: -1,
                        settingTypeInfo: t.settingTypeInfo
                    }
                }
            }
        });
        i.result.then(function() {
            s.systemsettingDic.clearCache();
            s.clearSystemSettingCache(n.itemType);
            t.browserSystemItemSetting(n)
        })
    };
    t.editSystemSettingItem = function(n) {
        n.itemType == "收费项目" ? o.valChargeTypeById(n.id).success(function(t) {
            t ? f.confirm("提示", "此收费项目已有过收费记录，修改后将影响统计报表，确定要修改此配置？").then(function() {
                y(n)
            }) : y(n)
        }) : y(n)
    };
    t.deleteSystemSettingItem = function(n) {
        if (n.itemType == "收费项目") {
            var i = t.getChildrenSystemSettingItems(n.itemType);
            o.listChargeItems().success(function(i) {
                for (var r = 0; r < i.length; r++)
                    if (i[r].itemCatagoryId == n.id) {
                        f.warn("信息", "该收费项目下有子项目未删除，请清空子项目后再删除收费项目！");
                        return
                    }
                o.valChargeTypeById(n.id).success(function(i) {
                    i ? f.confirm("提示", "此收费项目已有过收费记录，删除后将影响统计报表，确定要删除此配置？").then(function() {
                        o.getItemTypes(n.itemType).success(function() {
                            o.deleteSystemSettingItem(n.id).success(function() {
                                t.showNotification("删除成功！");
                                s.systemsettingDic.clearCache();
                                s.clearSystemSettingCache(n.itemType);
                                t.browserSystemItemSetting(n)
                            }).error(function() {
                                f.warn("信息", "删除失败")
                            })
                        })
                    }) : f.confirm("提示", "确定要删除此配置？").then(function() {
                        o.getItemTypes(n.itemType).success(function() {
                            o.deleteSystemSettingItem(n.id).success(function() {
                                t.showNotification("删除成功！");
                                s.systemsettingDic.clearCache();
                                s.clearSystemSettingCache(n.itemType);
                                t.browserSystemItemSetting(n)
                            }).error(function() {
                                f.warn("信息", "删除失败")
                            })
                        })
                    })
                })
            })
        } else n.itemType == "库存物品类别" ? o.listStockItems().success(function(i) {
            for (var r = 0; r < i.length; r++)
                if (i[r].itemType == n.itemName) {
                    f.warn("信息", "该库存类别下有子项目未删除，请清空子项目后再删除库存类别！");
                    return
                }
            f.confirm("提示", "确定要删除此配置？").then(function() {
                o.getItemTypes(n.itemType).success(function() {
                    o.deleteSystemSettingItem(n.id).success(function() {
                        t.showNotification("删除成功！");
                        s.systemsettingDic.clearCache();
                        s.clearSystemSettingCache(n.itemType);
                        t.browserSystemItemSetting(n)
                    }).error(function() {
                        f.warn("信息", "删除失败")
                    })
                })
            })
        }) : f.confirm("提示", "确定要删除此配置？").then(function() {
            o.getItemTypes(n.itemType).success(function() {
                o.deleteSystemSettingItem(n.id).success(function() {
                    t.showNotification("删除成功！");
                    s.systemsettingDic.clearCache();
                    s.clearSystemSettingCache(n.itemType);
                    t.browserSystemItemSetting(n)
                }).error(function() {
                    f.warn("信息", "删除失败")
                })
            })
        })
    };
    t.getTopLevelSettingItems = function(n) {
        var i;
        for (t.systemSettingTopLevel = [], t.systemSettingRoot = {}, i = 0; i < t.itemTypeList.length; ++i) t.systemSettingRoot[t.itemTypeList[i].key] = [], t.systemSettingTopLevel.push({
            itemKey: t.itemTypeList[i].key,
            itemName: t.itemTypeList[i].name || t.itemTypeList[i].key
        });
        for (i = 0; i < n.length; ++i) t.systemSettingRoot[n[i].itemType] && t.systemSettingRoot[n[i].itemType].push(n[i]);
        return t.systemSettingTopLevel
    };
    t.getChildrenSystemSettingItems = function(n) {
        var r, i, u;
        if (s.systemsettingDic.refresh().then(function(n) {
                t.systemSettingItems = n;
                t.getTopLevelSettingItems(t.systemSettingItems)
            }), t.systemSettingRoot && t.systemSettingRoot[n.itemKey]) {
            for (r = 0, i = 0; i < t.systemSettingRoot[n.itemKey].length; i++) t.systemSettingRoot[n.itemKey][i].index = r + 1, (t.systemSettingRoot[n.itemKey][i].displayOrder == null || t.systemSettingRoot[n.itemKey][i].displayOrder != r) && (t.systemSettingRoot[n.itemKey][i].displayOrder = r), r++, u = t.systemSettingRoot[n.itemKey][i].itemCode, t.settingTypeInfo.isDepartmentSetting && u && u.indexOf("@") == 0 && (t.systemSettingRoot[n.itemKey][i].itemCode = "");
            return t.systemSettingRoot[n.itemKey]
        }
        return null
    };
    t.isDisableDbClick = !1;
    var w = function(n, i) {
            var r, f, u, e;
            t.isDisableDbClick = !0;
            r = t.systemsettingList[i.displayOrder];
            f = i.displayOrder;
            t.systemsettingList.splice(i.displayOrder, 1, t.systemsettingList[n.displayOrder]);
            t.systemsettingList.splice(n.displayOrder, 1, r);
            u = n.displayOrder;
            e = n.index;
            t.systemsettingList[i.displayOrder].displayOrder = r.displayOrder;
            t.systemsettingList[u].displayOrder = u;
            t.systemsettingList[f].index = r.index;
            t.systemsettingList[u].index = e;
            o.updateSystemSettingItemList(t.systemsettingList).success(function() {
                t.refreshUpDownGrid(f);
                t.isDisableDbClick = !1;
                s.systemsettingDic.refresh()
            })
        },
        b = function(n, i) {
            var r, f, u, e;
            t.isDisableDbClick = !0;
            r = t.systemsettingList[n.displayOrder];
            f = n.displayOrder;
            t.systemsettingList.splice(n.displayOrder, 1, t.systemsettingList[i.displayOrder]);
            t.systemsettingList.splice(i.displayOrder, 1, r);
            u = i.displayOrder;
            e = i.index;
            t.systemsettingList[n.displayOrder].displayOrder = r.displayOrder;
            t.systemsettingList[u].displayOrder = u;
            t.systemsettingList[f].index = r.index;
            t.systemsettingList[u].index = e;
            o.updateSystemSettingItemList(t.systemsettingList).success(function() {
                t.refreshDownGrid(f);
                t.isDisableDbClick = !1;
                s.systemsettingDic.refresh()
            })
        },
        k = function() {
            t.itemTypeList = l.itemTypeList;
            var n = v.configKeys.IsRefundReasonEnabled;
            v.getConfigValue(n).then(function(n) {
                n || (t.itemTypeList = t.itemTypeList.filter(function(n) {
                    return n.key != "账单退费原因" && n.key != "账单作废原因" && n.key != "储值卡退款原因"
                }))
            })
        };
    (function() {
        k();
        var n = null;
        t.parentItem && (n = _.find(t.itemTypeList, {
            key: t.parentItem
        }));
        t.isSingleMode = n != null;
        t.browserSystemItemSetting(n);
        t.upItem = w;
        t.downItem = b
    })()
}]);
practiceModule.controller("PracticeSystemSettingEditCtrl", ["$log", "$scope", "$location", "$http", "$modalInstance", "aresDialog", "$state", "appNav", "practiceSvc", "patientSvc", "dataDicSvc", "enums", "constants", "loginContext", "host", "moduleOptionProvider", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y) {
    "use strict";
    var w, p;
    t.currentSystemSettingItem = {};
    t.itemTypeList = a.itemTypeList;
    t.cancel = function() {
        u.dismiss("cancel")
    };
    t.SystemSettingItems = {};
    t.saveSystemSettingItem = function() {
        var r, i, n;
        if (t.currentSystemSettingItem.itemName = t.currentSystemSettingItem.itemName.replace(/\s/g, ""), t.currentSystemSettingItem.itemType == "患者类型" && (r = RegExp(/[(\ )(\~)(\~)(\!)(\！)(\@)(\#)(\$)(\￥)(\%)(\^)(\……)(\&)(\*)(\()(\（)(\))(\）)(\-)(\_))(\——)(\+)(\=)(\[)(\【)(\])(\】)(\{)(\})(\|))(\、))(\)(\\)(\;)(\；)(\:)(\：)(\')(\‘)(\’)(\")(\“)(\”)(\,)(\，)(\.)(\。)(\/)(\《)(\<)(\>)(\》)(\?)(\？)(\)]+/), r.test(t.currentSystemSettingItem.itemName))) {
            f.warn("警告", "当前名称包含特殊字符，请更换新名称！");
            return
        }
        for (i = c.systemsettingDic.data(), n = 0; n < i.length; ++n)
            if (i[n].itemType == t.currentSystemSettingItem.itemType) {
                if (i[n].itemName == t.currentSystemSettingItem.itemName)
                    if (t.currentSystemSettingItem.id == i[n].id) continue;
                    else {
                        f.warn("警告", "已经有其他项目使用此名称，请更换新名称！");
                        return
                    }
                if (t.settingTypeInfo.isDepartmentSetting && t.currentSystemSettingItem.itemCode && i[n].itemCode == t.currentSystemSettingItem.itemCode)
                    if (t.currentSystemSettingItem.id == i[n].id) continue;
                    else {
                        f.warn("警告", "已经有其他项目使用此编码，请更换新编码！");
                        return
                    }
            }
        t.currentSystemSettingItem.id ? s.updateSystemSettingItem(t.currentSystemSettingItem).success(function(n) {
            t.showNotification("保存成功！");
            c.systemsettingDic.refresh();
            c.clearSystemSettingCache(n.itemType);
            u.close(n)
        }).error(function(n) {
            n.name == "SystemSettingItemNameNotUniqueException" ? (f.warn("警告", "已经有其他项目使用此名称，请更换新名称！"), init()) : n.name == "SystemSettingItemCodeNotUniqueException" && (f.warn("警告", "已经有其他项目使用此编码，请更换新编码！"), init())
        }) : s.createSystemSettingItem(t.currentSystemSettingItem).success(function(n) {
            t.showNotification("保存成功！");
            c.systemsettingDic.refresh();
            c.clearSystemSettingCache(n.itemType);
            u.close(n)
        }).error(function(n) {
            n.name == "SystemSettingItemNameNotUniqueException" ? (f.warn("警告", "已经有其他项目使用此名称，请更换新名称！"), init()) : n.name == "SystemSettingItemCodeNotUniqueException" && (f.warn("警告", "已经有其他项目使用此编码，请更换新编码！"), init())
        })
    };
    w = function() {
        jQuery.validator.addMethod("systemSettingName", function(n) {
            var u = !0,
                r, i;
            if (n)
                for (r = c.systemsettingDic.data(), i = 0; i < r.length; ++i)
                    if (r[i].itemType == t.currentSystemSettingItem.itemType && r[i].itemName == t.currentSystemSettingItem.itemName)
                        if (t.currentSystemSettingItem.id == r[i].id) continue;
                        else {
                            u = !1;
                            return
                        }
            return u
        }, "名称已被使用！")
    };
    w();
    t.parentCatagoryId = y.parentCatagoryId;
    t.systemsettingId = y.systemsettingId;
    t.settingTypeInfo = y.settingTypeInfo;
    y.displayOrder && (t.displayOrder = y.displayOrder);
    t.systemsettingId > 0 ? s.GetSystemSettingItemById(t.systemsettingId).success(function(n) {
        n && n.itemCode && n.itemCode.indexOf("@") == 0 && t.settingTypeInfo.isDepartmentSetting && (n.itemCode = "");
        t.currentSystemSettingItem = n;
        var i = _.find(t.itemTypeList, {
            key: n.itemType
        });
        t.currentSystemSettingItem.itemTypeName = i.name || i.key
    }) : (p = t.itemTypeList[t.parentCatagoryId], t.currentSystemSettingItem = {
        id: 0,
        itemName: "",
        itemType: p.key,
        itemTypeName: p.name || p.key,
        displayOrder: t.displayOrder,
        itemCode: ""
    })
}]);
practiceModule.controller("PracticeSystemsettingTransactioncodeEditCtrl", ["$log", "$scope", "$modalInstance", "host", "$modal", "transactionCodeSvc", "aresDialog", "dataDicSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function(n, t) {
            this.name = n;
            this.value = t
        },
        c = [new s("粉色20", "#f988e2"), new s("紫色20", "#d695ff"), new s("靛蓝20", "#94aefb"), new s("水绿20", "#73e7d6"), new s("绿色20", "#74ea92"), new s("绿黄20", "#cfef77"), new s("黄色20", "#ffdc7f"), new s("橙色20", "#ffbb81"), new s("红色20", "#f99299"), new s("粉色30", "#f160d4"), new s("紫色30", "#c974ff"), new s("靛蓝30", "#7395fb"), new s("水绿30", "#47d8c2"), new s("绿色30", "#48dd6d"), new s("绿黄30", "#b9e24a"), new s("黄色30", "#f9cc51"), new s("橙色30", "#f9a051"), new s("红色30", "#f6717a"), new s("粉色40", "#e238c0"), new s("紫色40", "#b84ff9"), new s("靛蓝40", "#507bfb"), new s("水绿40", "#21c8af"), new s("绿色40", "#22ce4d"), new s("绿黄40", "#a4d323"), new s("黄色40", "#efba28"), new s("橙色40", "#f18628"), new s("红色40", "#ec4b56"), ],
        h = _.map(c, function(n) {
            return n.value
        }),
        l = function() {
            h.length = c.length;
            h.push("#FFFFFF");
            angular.forEach(t.transactioncodes, function(n) {
                var t = n.color;
                (t == "#ffffff" || t == "#FFFFFF" || t == "transparent") && (t = null);
                t && h.indexOf(t) < 0 && h.push(t)
            })
        },
        a = function() {
            o.systemsettingDic.loadActive({
                itemType: "预约大类"
            }).then(function(n) {
                n.push({
                    itemName: "其他"
                });
                t.categories = n
            })
        },
        v = function() {
            a();
            r.transactioncode ? (t.title = "编辑", t.transactioncode = r.transactioncode) : (t.title = "新建", t.transactioncode = {
                name: "",
                color: null,
                seqNum: _.max(t.transactioncodes, function(n) {
                    return n.seqNum
                }).seqNum + 1e3,
                category: r.catagory
            });
            l()
        },
        y = function() {
            t.transactioncode.codeType = 0;
            t.transactioncode.id > 0 ? f.update(t.transactioncode).success(function() {
                o.transactionCodeDic.refresh().then(function() {
                    i.close(!0)
                })
            }).error(function(t) {
                t.name == "TransactionCodeNotUniqueException" ? e.warn("提示", "该项目已经存在！") : n.error(t)
            }) : f.add(t.transactioncode).success(function() {
                o.transactionCodeDic.refresh().then(function() {
                    i.close(!0)
                });
                i.close(!0)
            }).error(function(t) {
                t.name == "TransactionCodeNotUniqueException" ? e.warn("提示", "该项目已经存在！") : n.error(t)
            })
        },
        p = function() {
            i.close()
        };
    (function() {
        t.transactioncodes = r.transactioncodes;
        t.procedureColors = c;
        t.colorValues = h;
        t.cancel = p;
        t.save = y;
        v()
    })()
}]);
practiceModule.controller("PracticeSystemsettingTransactioncodeCtrl", ["$log", "$timeout", "$scope", "$modal", "aresDialog", "transactionCodeSvc", "dataDicSvc", "apptUtil", function(n, t, i, r, u, f, e, o) {
    "use strict";
    i.chargeCatagory = [];
    i.isAllCharge = !1;
    var c, l = !1,
        h = !1,
        p = function(n, t) {
            var r, u, f;
            l = !0;
            r = n.seqNum;
            n.seqNum = t.seqNum;
            t.seqNum = r;
            u = _.find(i.transactioncodes, function(t) {
                return t.id == n.id
            });
            u.seqNum = n.seqNum;
            f = _.find(i.transactioncodes, function(n) {
                return n.id == t.id
            });
            f.seqNum = t.seqNum;
            i.transactioncodes.splice(r - 1, 1, f);
            i.transactioncodes.splice(r - 2, 1, u);
            i.refreshUpDownGrid(r);
            y()
        },
        w = function(n, t) {
            var r, u, f;
            l = !0;
            r = n.seqNum;
            n.seqNum = t.seqNum;
            t.seqNum = r;
            u = _.find(i.transactioncodes, function(t) {
                return t.id == n.id
            });
            u.seqNum = n.seqNum;
            f = _.find(i.transactioncodes, function(n) {
                return n.id == t.id
            });
            f.seqNum = t.seqNum;
            i.transactioncodes.splice(r - 1, 1, f);
            i.transactioncodes.splice(r, 1, u);
            i.refreshDownGrid(r);
            y()
        },
        v = function() {
            e.systemsettingDic.load().then(function(n) {
                if (i.chargeItemTreeData = new kendo.data.HierarchicalDataSource({
                        data: b(n)
                    }), i.currentChargeItemCatagory) s(i.currentChargeItemCatagory.itemName);
                else if (i.chargeCatagory) {
                    var r = $("#itemlist").data("kendoTreeView");
                    t(function() {
                        $("#itemlist").data("kendoTreeView").select(".k-first")
                    }, 50)
                }
            })
        };
    i.onChargeItemCatagoryChange = function(n) {
        n && (l ? f.updateList(i.transactioncodes).success(function() {
            h ? e.transactionCodeDic.refresh().then(function() {
                h = !1;
                i.isAllCharge = !1;
                i.currentChargeItemCatagory = n;
                s(n.itemName)
            }) : (i.isAllCharge = !1, i.currentChargeItemCatagory = n, s(n.itemName))
        }) : h ? e.transactionCodeDic.refresh().then(function() {
            h = !1;
            i.isAllCharge = !1;
            i.currentChargeItemCatagory = n;
            s(n.itemName)
        }) : (i.isAllCharge = !1, i.currentChargeItemCatagory = n, s(n.itemName)))
    };
    var a = function() {
            i.isAllCharge = !0;
            i.currentChargeItemCatagory = null;
            var n = $("#itemlist").data("kendoTreeView");
            n.select($());
            f.getAllActive().success(function(n) {
                var n, t;
                if (n) {
                    for (n = o.sortCodes(n), t = 0; t < n.length; ++t) n[t].seqNum = t + 1, n[t].category || (n[t].category = "其他");
                    i.transactioncodes = n
                } else i.transactioncodes = []
            })
        },
        b = function(n) {
            if (i.chargeCatagory && i.chargeCatagory.length > 0) return i.chargeCatagory;
            i.chargeCatagory = [];
            for (var t = 0; t < n.length; ++t) n[t].itemType == "预约大类" && i.chargeCatagory.push(n[t]);
            return i.chargeCatagory.push({
                itemName: "其他",
                itemType: "预约大类"
            }), i.chargeCatagory
        },
        s = function(n) {
            f.getByCategory(n).success(function(n) {
                if (n) {
                    for (var t = 0; t < n.length; t++) n[t].seqNum = t + 1, n[t].category || (n[t].category = "其他");
                    i.transactioncodes = n
                } else i.transactioncodes = []
            })
        },
        k = function(n) {
            var t, f, e;
            if (n) f = angular.copy(n);
            else {
                if (!i.currentChargeItemCatagory) {
                    u.info("信息", "请先选择一个预约项目大类!");
                    return
                }
                t = i.currentChargeItemCatagory.itemName
            }
            e = r.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-systemsetting-transactioncode-edit-view><\/practice-systemsetting-transactioncode-edit-view>",
                controller: "PracticeSystemsettingTransactioncodeEditCtrl",
                windowClass: "image-appointments-select-dialog",
                resolve: {
                    host: function() {
                        return {
                            catagory: t,
                            transactioncodes: i.transactioncodes,
                            transactioncode: f
                        }
                    }
                }
            });
            e.result.then(function(n) {
                n && (i.currentChargeItemCatagory ? s(i.currentChargeItemCatagory.itemName) : a())
            })
        },
        d = function(n) {
            u.confirm("提示", "您确认要删除吗？").then(function() {
                f.destroy(n).success(function() {
                    h = !0;
                    i.currentChargeItemCatagory ? s(i.currentChargeItemCatagory.itemName) : i.isAllCharge ? a() : v();
                    e.transactionCodeDic.refresh().then(function() {
                        h = !1
                    })
                })
            })
        },
        y = function() {
            c && t.cancel(c);
            c = t(function() {
                f.updateList(i.transactioncodes).success(function() {
                    e.transactionCodeDic.refresh().then(function() {
                        l = !1
                    })
                })
            }, 2e3)
        };
    i.upItem = p;
    i.downItem = w;
    i.AllChargeItem = a;
    i.openEditDialog = k;
    i.destroy = d;
    v();
    i.$on("$destroy", function() {
        c && t.cancel(c);
        f.updateList(i.transactioncodes).success(function() {
            e.transactionCodeDic.refresh()
        })
    })
}]);
practiceModule.controller("PracticeTxplanItemCodeConfigCtrl", ["$log", "$scope", "$modalInstance", "host", "$modal", "aresDialog", "enums", "commonRuleSvc", "dataDicSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var h = {
            sequenceType: e.SequenceType.TxPlanCode,
            prefix: "L",
            dateFormat: null,
            seqNumberDigits: 4
        },
        s = !1,
        c = function() {
            i.close()
        },
        l = function() {
            o.getBySequenceType(e.SequenceType.TxPlanCode).success(function(n) {
                n ? (s = !0, t.commonRule = n) : (s = !1, t.commonRule = h)
            })
        },
        a = function() {
            t.commonRule.seqNumberDigits = t.commonRule.seqNumberDigits || 2;
            s ? o.update(t.commonRule).success(function() {
                i.close(!0)
            }) : o.add(t.commonRule).success(function() {
                i.close(!0)
            })
        },
        v = function() {
            for (var r = t.commonRule.prefix, n = "", i = 1; i <= t.commonRule.seqNumberDigits; i++) n += i == t.commonRule.seqNumberDigits ? 1 : 0;
            return n || (n = "01"), r + n
        };
    (function() {
        t.cancel = c;
        t.save = a;
        l();
        t.$watchCollection("commonRule", function() {
            if (t.commonRule) {
                var n = $("#codeNumber").val();
                n > 8 ? t.commonRule.seqNumberDigits = 8 : t.commonRule.seqNumberDigits === undefined && (t.commonRule.seqNumberDigits = 2);
                t.viewCode = v()
            }
        })
    })()
}]);
practiceModule.controller("PracticeTxplanItemEditCtrl", ["$log", "$scope", "$q", "$modalInstance", "host", "$modal", "aresDialog", "practiceSvc", "transactionCodeSvc", "dataDicSvc", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    var v = function() {
            u.txplanId ? (t.title = "编辑治疗计划项目", s.getTxPlanById(u.txplanId).success(function(n) {
                var i;
                for (n.showPrice = angular.copy(n.price), n.chargeItemList = [], n.diagnoseItem = [], i = 0; i < n.chargeDetails.length; i++) n.chargeDetails[i].chargeItem.count = n.chargeDetails[i].count, n.chargeItemList.push(n.chargeDetails[i].chargeItem);
                for (i = 0; i < n.diagnoses.length; i++) n.diagnoseItem.push(n.diagnoses[i].diagnoseItem);
                t.txPlan = n
            })) : (t.title = "新建治疗计划项目", a().then(function(n) {
                t.txPlan = {
                    codeType: 1,
                    code: n,
                    isInactive: !1,
                    showPrice: 0,
                    seqNum: 0,
                    chargeDetails: [],
                    diagnoses: []
                }
            }))
        },
        y = function() {
            var n = f.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-txplan-item-plan-view><\/practice-txplan-item-plan-view>",
                controller: "PracticeTxplanItemPlanCtrl",
                windowClass: "membership-discountplan-detail-dialog",
                resolve: {
                    host: function() {
                        return {
                            chargeItemList: t.txPlan.chargeItemList
                        }
                    }
                }
            });
            n.result.then(function(n) {
                n && (t.txPlan.chargeItemList = n, c(t.txPlan.chargeItemList))
            })
        },
        c = function(n) {
            t.txPlan.showPrice = 0;
            for (var i = 0; i < n.length; i++) t.txPlan.showPrice += n[i].price * n[i].count
        },
        p = function(n) {
            t.txPlan.chargeItemList.splice(n, 1);
            c(t.txPlan.chargeItemList)
        },
        w = function(n, i) {
            var u = n.sender,
                r = u.value();
            r == null && (u.value(1), t.txPlan.chargeItemList[i].count = 1, r = 1);
            t.txPlan.chargeItemList[i].count = r;
            c(t.txPlan.chargeItemList)
        },
        b = function() {
            if (!t.txPlan.code) {
                e.info("提示", "项目代码不能为空!");
                return
            }
            if (!t.txPlan.name) {
                e.info("提示", "项目名称不能为空!");
                return
            }
            if (!t.txPlan.diagnoseItem || !t.txPlan.diagnoseItem.length) {
                e.info("提示", "关联诊断不能为空!");
                return
            }
            t.save()
        },
        k = function() {
            var n;
            for (t.txPlan.price = angular.copy(t.txPlan.showPrice), t.txPlan.diagnoses = [], n = 0; n < t.txPlan.diagnoseItem.length; n++) t.txPlan.diagnoseItem[n].id ? t.txPlan.diagnoses.push({
                diagnoseItemId: t.txPlan.diagnoseItem[n].id
            }) : t.txPlan.diagnoses.push({
                diagnoseItemId: t.txPlan.diagnoseItem[n]
            });
            if (t.txPlan.chargeDetails = [], t.txPlan.chargeItemList)
                for (n = 0; n < t.txPlan.chargeItemList.length; n++) t.txPlan.chargeDetails.push({
                    chargeItemId: t.txPlan.chargeItemList[n].id,
                    count: t.txPlan.chargeItemList[n].count
                });
            t.txPlan.id > 0 ? d() : s.add(t.txPlan).success(function(n) {
                h.txplanItemDic.refresh();
                n && r.close(t.txPlan)
            }).error(function(n) {
                n.name === "TransactionCodeNotUniqueException" ? e.warn("提示", "该项目代码已经存在！") : n.name === "TransactionCodeNameNotUniqueException" && e.warn("提示", "该项目名称已经存在！")
            })
        },
        d = function() {
            s.updateTxplan(t.txPlan).success(function(n) {
                h.txplanItemDic.refresh();
                n && r.close(n)
            }).error(function(n) {
                n.name === "TransactionCodeNotUniqueException" ? e.warn("提示", "该项目代码已经存在！") : n.name === "TransactionCodeNameNotUniqueException" && e.warn("提示", "该项目名称已经存在！")
            })
        },
        g = function() {
            r.close()
        },
        nt = function() {
            var n = f.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-txplan-item-code-config-view><\/practice-txplan-item-code-config-view>",
                controller: "PracticeTxplanItemCodeConfigCtrl",
                size: "sm",
                resolve: {
                    host: null
                }
            });
            n.result.then(function(n) {
                n && l()
            })
        },
        l = function() {
            a().then(function(n) {
                t.txPlan.code = n
            })
        },
        a = function() {
            var n = i.defer();
            return s.generateTxPlanCode().success(function(t) {
                n.resolve(t)
            }), n.promise
        };
    (function() {
        t.refTPCode = l;
        t.addChargeItem = y;
        t.deleteChargeItem = p;
        t.saveCheck = b;
        t.save = k;
        t.cancel = g;
        t.onItemCountChange = w;
        t.openItemCodeConfigDialog = nt;
        v()
    })()
}]);
practiceModule.controller("PracticeTxplanItemPlanCtrl", ["$log", "$scope", "$modalInstance", "$q", "membershipSvc", "aresDialog", "dataDicSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = {},
        h = {},
        l = function(n) {
            var r = n[0],
                u = n[1],
                f = n[2],
                i;
            t.chargeSupCatagoryList = [];
            r.forEach(function(n) {
                t.chargeSupCatagoryList.push(n);
                s[n.id] = []
            });
            u.forEach(function(n) {
                var i = _.findIndex(t.chargeSupCatagoryList, function(t) {
                    return n.itemSuperCategoryId == t.id ? !0 : !1
                });
                i != -1 && (s[n.itemSuperCategoryId].push(n), h[n.id] = [])
            });
            f.forEach(function(n) {
                var t = s[n.itemSuperCategoryId],
                    i;
                if (t) {
                    if (i = _.findIndex(t, function(t) {
                            return n.itemCatagoryId == t.id ? !0 : !1
                        }), i == -1) return
                } else return;
                h[n.itemCatagoryId].push(n)
            });
            t.defaultSupCategoryId = t.chargeSupCatagoryList.length > 0 ? t.chargeSupCatagoryList[0].id : 0;
            t.chargeCatagoryList = s[t.defaultSupCategoryId];
            t.chargeCatagoryList && t.chargeCatagoryList.length > 0 && (t.defaultCategoryId = t.chargeCatagoryList[0].id);
            i = h[t.defaultCategoryId].filter(function(n) {
                return n.chargeItemType == 0
            });
            t.chargeItemList = i;
            c()
        },
        a = function() {
            t.giftPlanList = [];
            t.existList && t.existList.length > 0 && _.each(t.existList, function(n) {
                t.giftPlanList.push(n)
            })
        },
        v = function() {
            i.dismiss("cancel")
        },
        y = function() {
            i.close(t.giftPlanList)
        },
        p = function(n, i) {
            t.chargeItemList = null;
            n ? (t.chargeItemList = h[n], c()) : i && (t.chargeCatagoryList = s[i], t.chargeCatagoryList && t.chargeCatagoryList.length > 0 && (t.defaultCategoryId = t.chargeCatagoryList[0].id, t.chargeItemList = h[t.defaultCategoryId], c()))
        },
        c = function() {
            o.chargeItemFilterMethod && _.isFunction(o.chargeItemFilterMethod) && (t.chargeItemList = o.chargeItemFilterMethod(t.chargeItemList))
        };
    (function() {
        t.existList = o.chargeItemList;
        t.save = y;
        t.cancel = v;
        t.resetChargeItemList = p;
        t.chargeSupCatagoryList = null;
        t.chargeCatagoryList = null;
        t.chargeItemList = null;
        t.defaultSupCategoryId = 0;
        t.defaultCategoryId = 0;
        a();
        r.all([e.chargeSuperCategoryDic.load(), e.chargeCategoryDic.load(), e.chargeItemDic.load(), ]).then(function(n) {
            l(n)
        })
    })()
}]);
practiceModule.controller("PracticeTxplanItemCtrl", ["$log", "$timeout", "$scope", "$modal", "aresDialog", "aresNotification", "transactionCodeSvc", "dataDicSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function() {
            var n = i.showIsEableOrAll ? "getAllTxPlan" : "getAllActiveTxPlan";
            e[n]().success(function(n) {
                n && (angular.forEach(n, function(n) {
                    n.price = n.price;
                    n.isInactiveStr = n.isInactive ? "禁用" : "启用"
                }), i.txPlanList = n)
            })
        },
        h = function(n) {
            var t = r.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-txplan-item-edit-view><\/practice-txplan-item-edit-view>",
                controller: "PracticeTxplanItemEditCtrl",
                resolve: {
                    host: function() {
                        return {
                            txplanId: n
                        }
                    }
                }
            });
            t.result.then(function(n) {
                n && s()
            })
        },
        c = function(n) {
            if (n.isDefault) {
                i.showErrorNotification("默认项目不允许删除！");
                return
            }
            u.confirm("提示", "您确认要删除吗？").then(function() {
                l(n.id)
            })
        },
        l = function(n) {
            e.deleteTransactionCode(n).success(function() {
                s();
                o.transactionCodeDic.refresh()
            }).error(function(n) {
                n.name == "TransactionCodeHasUseException" && i.showErrorNotification("该项目已被使用，无法删除！")
            })
        };
    (function() {
        i.showIsEableOrAll = !1;
        i.openEditDialog = h;
        i.deleteTxPlan = c;
        i.$watch("showIsEableOrAll", function() {
            s()
        });
        i.$on("$destroy", function() {})
    })()
}]);
practiceModule.controller("PracticeChargeCategoryEditCtrl", ["$q", "$scope", "officeSvc", "dataDicSvc", "$modalInstance", "host", "loginContext", "chargeItemSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function() {
            u.dismiss("close")
        },
        h = function(t) {
            var i = n.defer(),
                f;
            return f = t.id > 0 ? o.updateChargeItemCategory({
                id: t.id,
                itemName: t.itemName,
                itemEnglishName: t.itemEnglishName,
                itemSuperCategoryId: t.itemSuperCategoryId,
                itemSuperCategoryName: t.itemSuperCategoryName,
                isInDeal: t.isInDeal,
                syncOptions: t.syncOptions
            }) : o.createChargeItemCategory({
                itemName: t.itemName,
                itemEnglishName: t.itemEnglishName,
                itemSuperCategoryId: t.itemSuperCategoryId,
                itemSuperCategoryName: t.itemSuperCategoryName,
                isInDeal: t.isInDeal,
                displayOrder: t.displayOrder,
                syncOptions: t.syncOptions
            }), f.success(function(n) {
                r.chargeItemDic.refresh();
                u.close(n);
                i.resolve()
            }).error(function() {
                i.reject()
            }), i.promise
        },
        c = function() {
            var t = n.defer(),
                r = e.officeId;
            return i.getOfficeNodesByParent(r).success(function(n) {
                var i = n.filter(function(n) {
                    return n.bizType == 1
                });
                t.resolve(i)
            }), t.promise
        },
        l = function() {
            var i = n.defer();
            return o.getSyncInfo("ChargeItemCategory", t.category.id).success(function(n) {
                i.resolve(n)
            }), i.promise
        };
    (function() {
        t.checkNewItemNameUnique = f.checkNewItemNameUnique;
        t.superCategoryList = f.superCategoryList;
        t.category = f.category;
        t.close = s;
        t.save = h;
        t.getOrganizationInfo = c;
        t.getCategorySyncOptions = l
    })()
}]);
practiceModule.controller("PracticeChargeCategoryCtrl", ["$log", "$q", "$scope", "$timeout", "dataDicSvc", "chargeItemSvc", "permissionProvider", "constants", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function(n) {
            return n && u.chargeSuperCategoryDic.clearCache(), u.chargeSuperCategoryDic.load().then(function(n) {
                i.chargeItemSuperCategorys = n
            })
        },
        h = function(n) {
            return n && u.chargeCategoryDic.clearCache(), u.chargeCategoryDic.load().then(function(n) {
                i.chargeItemCategorys = n
            })
        },
        a = function() {
            return u.chargePackageDic.load().then(function(n) {
                i.chargePackages = n
            })
        },
        c = function(n) {
            return n && u.chargeItemDic.clearCache(), u.chargeItemDic.load().then(function(n) {
                i.chargeItems = n
            })
        },
        v = function(n) {
            var r = t.defer(),
                u = _.find(i.chargeItemSuperCategorys, function(t) {
                    return n === t.id
                });
            return r.resolve(u.catagoryItems), r.promise
        },
        y = function(n) {
            return f.deleteChargeItemCategory(n).success(function(n) {
                return n
            })
        },
        p = function(n) {
            var i = t.defer();
            return f.checkCategoryItemHasChargeItem(n).success(function(n) {
                n ? i.resolve() : i.reject()
            }), i.promise
        },
        w = function(n) {
            var i = t.defer();
            return f.checkCategoryItemUsedChargeOrder(n).success(function(n) {
                i.resolve(n)
            }), i.promise
        },
        b = function(n) {
            return f.updateCategoryItemList(n).then(function() {
                u.chargeCategoryDic.clearCache()
            })
        },
        k = function(n) {
            return f.deleteChargeItemSuperCategory(n).success(function(n) {
                return n
            })
        },
        d = function(n) {
            var r = t.defer(),
                u = _.find(i.chargeItemSuperCategorys, function(t) {
                    return t.id === n
                });
            return u.catagoryItems.length > 1 ? r.resolve() : r.reject(), r.promise
        },
        g = function(n) {
            var i = t.defer();
            return f.checkSuperCategoryItemUsedChargeOrder(n).success(function(n) {
                i.resolve(n)
            }), i.promise
        },
        nt = function(n) {
            return f.updateSuperCategoryItemList(n).then(function() {
                u.chargeSuperCategoryDic.clearCache()
            })
        },
        tt = function(n, t, r) {
            var e = i.chargePackages.filter(function(t) {
                    return t.name == n
                }),
                o = i.chargeItems.filter(function(t) {
                    return t.itemName == n
                }),
                u = i.chargeItemCategorys.filter(function(t) {
                    return t.itemName == n
                }),
                f = i.chargeItemSuperCategorys.filter(function(t) {
                    return t.itemName == n
                });
            return t && (u = u.filter(function(n) {
                return n.id != t
            })), r && (f = f.filter(function(n) {
                return n.id != r
            })), e.length == 0 && o.length === 0 && u.length === 0 && f.length === 0
        },
        l = function() {
            for (var t, r, n = 0; n < i.chargeItemSuperCategorys.length; n++) t = i.chargeItemSuperCategorys[n], t.displayOrder = n + 1, r = i.chargeItemCategorys.filter(function(n) {
                return n.itemSuperCategoryId === t.id
            }), r.forEach(function(n, t) {
                n.displayOrder = t + 1
            }), i.isChargeItemEditAllowed && t.itemName != o.ValueAddSuperCategoryName && r.push({
                id: 0,
                itemName: "添加小类"
            }), t.catagoryItems = r
        },
        rt = function(n) {
            var t = i.chargeItems.filter(function(t) {
                return t.itemCatagoryId == n && !t.isInDeal
            });
            return !t || t.length == 0
        },
        it = function() {
            t.all([s(), h(), c(), a()]).then(function() {
                l();
                i.initView()
            })
        };
    (function() {
        it();
        i.initData = l;
        i.checkNewItemNameUnique = tt;
        i.getCategoryListPromise = h;
        i.getSuperCategoryListPromise = s;
        i.getCategoryListBySuperCategoryPromise = v;
        i.getChargeItemListPromise = c;
        i.deleteCategoryItemPromise = y;
        i.checkCategoryItemHasChargeItemPromise = p;
        i.checkCategoryItemUsedChargeOrderPromise = w;
        i.updateCategoryItemListPromise = b;
        i.deleteSuperCategoryItemPromise = k;
        i.checkSuperCategoryItemHasCategoryItemPromise = d;
        i.checkSuperCategoryItemUsedChargeOrderPromise = g;
        i.updateSuperCategoryItemListPromise = nt;
        i.isChargeItemEditAllowed = e.isChargeItemEditAllowed
    })()
}]);
patientModule.controller("PracticeChargeDeductionItemsCtrl", ["$log", "$scope", "$modalInstance", "$q", "host", "deductionSvc", function(n, t, i, r, u, f) {
    "use strict";
    t.searchCriteria = {};
    var e = function() {
            var n = r.defer(),
                i = [];
            return i.push(o()), r.all(i).then(function() {
                n.resolve(t.deductionItems)
            }), n.promise
        },
        o = function() {
            var n = r.defer();
            return t.searchCriteria.pageSize = t.pageSize, t.searchCriteria.pageIndex = t.pageIndex, t.searchCriteria.orderField = t.sortField, t.searchCriteria.sortDirection = t.sortDirection, t.searchCriteria.deductionPlanId = u.deductionPlanId, f.getItemList(t.searchCriteria).success(function(i) {
                t.deductionItems = i;
                n.resolve(!0)
            }), n.promise
        },
        s = function() {
            i.dismiss("cancel")
        };
    (function() {
        t.maxPageCount = 15;
        t.onPageChanged = e;
        t.cancel = s
    })()
}]);
practiceModule.controller("PracticeChargeDeductionPlanCtrl", ["$log", "$q", "$scope", "$timeout", "dataDicSvc", "aresNotification", "deductionSvc", "systemConfigUtil", "followupSvc", "permissionProvider", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    var l = function() {
            var s = i.selectedDeductionPlan,
                t;
            if (!s.planName) return f.error("划扣方案名称不能为空"), !1;
            if (t = i.deductionPlanList.filter(function(n) {
                    var t = !0;
                    return i.selectedDeductionPlan.id && (t &= n.id != i.selectedDeductionPlan.id), t & n.planName == i.selectedDeductionPlan.planName
                }), t.length) return f.error("划扣方案名称不能重复"), !1;
            var r = [],
                u = !1,
                n = 0,
                e = !0,
                o = !0;
            return (i.selectedDeductionPlan.steps.forEach(function(t) {
                t.stepName || r.push(t);
                u |= i.selectedDeductionPlan.steps.filter(function(n) {
                    return n.stepName == t.stepName
                }).length > 1;
                n = Ares.priceToFixed(n + parseFloat(t.stepRatio));
                e &= !i.allowChargeDeductionManHours || t.manHourCount == null || 0 < t.manHourCount;
                o &= !t.isRepeatable || 1 < t.defaultRepeatCount && t.defaultRepeatCount < 100
            }), r.length > 0) ? (f.error("治疗步骤名称不能为空"), !1) : u ? (f.error("治疗步骤名称不能重复"), !1) : n != 100 ? (f.error("治疗步骤划扣比例之和不是100%"), !1) : e ? o ? !0 : (f.error("默认划扣次数填写错误，只能填写2-99之间的整数。"), !1) : (f.error("默认工时填写错误，只能填写大于0的整数。"), !1)
        },
        a = function() {
            if (l()) {
                var n;
                n = i.selectedDeductionPlan.id ? e.updatePlan(i.selectedDeductionPlan) : e.createPlan(i.selectedDeductionPlan);
                n.success(function(n) {
                    f.success("保存成功");
                    i.selectedDeductionPlan = n;
                    i.srcEditDeductionPlan = n;
                    c();
                    i.isEdit = !1
                }).error(function(n) {
                    n.name == "DeductionPlanBoundException" && i.selectedDeductionPlan.id ? f.error("划扣方案已被绑定收费项目，无法更新") : f.error("保存失败")
                })
            }
        },
        v = function(n) {
            e.deletePlan(n).success(function() {
                n == i.selectedDeductionPlan.id && (i.selectedDeductionPlan = null, i.srcEditDeductionPlan = null);
                f.success("删除成功");
                c(!1, !0)
            }).error(function(n) {
                n.name == "DeductionPlanBoundException" ? f.error("划扣方案已被绑定收费项目，无法删除") : f.error("删除失败")
            })
        },
        c = function(n, t) {
            e.getPlanList().success(function(r) {
                i.deductionPlanList = r;
                !i.selectedDeductionPlan && r.length && (i.selectedDeductionPlan = angular.copy(r[0]));
                n ? i.initListView() : i.updateListView(t)
            })
        },
        y = function() {
            o.getConfigValue(o.configKeys.AllowChargeDeductionManHours).then(function(n) {
                i.allowChargeDeductionManHours = n
            });
            o.getConfigValue(o.configKeys.IsShowAutoDeductionExecuteSwitchEnabled).then(function(n) {
                i.isShowAutoDeductionExecuteSwitchEnabled = n
            });
            s.getRuleLites().then(function(n) {
                i.followupRuleLites = n.data
            })
        };
    (function() {
        i.save = a;
        i.deletePlan = v;
        i.isChargeItemEditAllowed = h.isChargeItemEditAllowed;
        y();
        c(!0)
    })()
}]);
var charge;
(function(n) {
    var t = function() {
        function n(n, t, i, r, u, f, e, o) {
            this.$log = n;
            this.$q = t;
            this.$scope = i;
            this.$timeout = r;
            this.$modalInstance = u;
            this.host = f;
            this.aresNotification = e;
            this.chargeItemSvc = o;
            i.category = f.category;
            i.categoryList = f.categoryList;
            i.parentCategory = f.parentCategory;
            this.init()
        }
        return n.prototype.cancel = function() {
            this.$modalInstance.dismiss("close")
        }, n.prototype.close = function(n) {
            this.$modalInstance.close(n)
        }, n.prototype.init = function() {
            this.$scope.category.id || (this.$scope.category.name = "")
        }, n.prototype.checkNewItemNameUnique = function(n, t) {
            return t.some(function(t) {
                return t == n
            })
        }, n.prototype.save = function() {
            var n = this,
                t = this.$scope.category.name.trim(),
                i;
            if (!t) return this.aresNotification.error("类目名称不能为空！"), !1;
            if (i = this.$scope.categoryList.filter(function(t) {
                    return t.id != n.$scope.category.id && n.$scope.category.id
                }).map(function(n) {
                    return n.name.trim()
                }), this.checkNewItemNameUnique(t, i)) return this.aresNotification.error("类目名称已被使用！"), !1;
            this.chargeItemSvc.addOrUpdateChargeItemFavoriteCategory(this.$scope.category).then(function(t) {
                var i = t.data;
                n.close(i)
            })
        }, n.$inject = ["$log", "$q", "$scope", "$timeout", "$modalInstance", "host", "aresNotification", "chargeItemSvc"], n
    }();
    n.PracticeChargeItemFavoriteEditCtrl = t;
    chargeModule.controller("PracticeChargeItemFavoriteEditCtrl", Ares.tsController(t))
})(charge || (charge = {}));
var charge;
(function(n) {
    var t = function() {
        function n(n, t, i, r, u, f, e, o, s, h, c, l) {
            var a = this;
            this.$log = n;
            this.$q = t;
            this.$scope = i;
            this.$timeout = r;
            this.chargeItemSvc = u;
            this.dataDicSvc = f;
            this.permissionProvider = e;
            this.aresTreeControlUtil = o;
            this.$modal = s;
            this.aresNotification = h;
            this.aresConfirmDialog = c;
            this.loginContext = l;
            i.chargePackageList = {};
            i.isDisableDbClick = !1;
            this.initData().then(function() {
                a.constructTreeData(a.$scope.chargeItemFavoriteCategoryList)
            })
        }
        return n.prototype.initConfig = function() {
            var n = this,
                t = this.$q.defer();
            return this.dataDicSvc.officeBaseDataOptionDic.load().then(function(i) {
                var r = _.find(i, function(n) {
                    return n.category == 1
                });
                n.$scope.chargeItemAboutEnabled = r && r.isParentEnabled ? !1 : !0;
                t.resolve()
            }), t.promise
        }, n.prototype.initChargeItemFavorites = function(n) {
            var r = this,
                t, i;
            return n === void 0 && (n = !1), t = this.$q.defer(), i = this.loginContext.userId, n && this.dataDicSvc.chargeItemFavoriteDic.clearCache(), this.dataDicSvc.chargeItemFavoriteDic.load(function(n) {
                return n.userId == i
            }).then(function(n) {
                for (var i, f = 0, u = 0; u < n.length; u++) i = n[u], i.index = u + 1, (i.displayOrder == null || i.displayOrder != f) && (i.displayOrder = f), i.categoryId || (i.categoryId = 0), i.cate && f++;
                r.$scope.chargeItemFavoriteList = n;
                t.resolve()
            }), t.promise
        }, n.prototype.initChargeItemFavoriteCategorys = function(n) {
            var r = this,
                t, i;
            return n === void 0 && (n = !1), t = this.$q.defer(), i = this.loginContext.userId, n && this.dataDicSvc.chargeItemFavoriteCategoryDic.clearCache(), this.dataDicSvc.chargeItemFavoriteCategoryDic.load(function(n) {
                return n.userId == i
            }).then(function(n) {
                for (var i, f = 0, e = [{
                        name: "常用项目",
                        parentId: 0,
                        id: 0,
                        ownerId: null,
                        index: 0,
                        displayOrder: 0
                    }].concat(n), u = 0; u < e.length; u++) i = e[u], i.index = u + 1, (i.displayOrder == null || i.displayOrder != f) && (i.displayOrder = f), i.name = i.name, f++;
                r.$scope.chargeItemFavoriteCategoryList = e;
                t.resolve()
            }), t.promise
        }, n.prototype.initData = function() {
            var t = this,
                n;
            return this.$scope.treeOpts = {
                addLeafBtnTitle: "添加常用收费项目",
                showActionBar: this.permissionProvider.isChargeItemEditAllowed,
                showLeafs: !1,
                dirSelectable: !0
            }, n = this.dataDicSvc.chargeItemDic.load().then(function(n) {
                t.$scope.srcChargeItems = n
            }), this.$scope.isDialog = !1, this.$q.all([this.initConfig(), this.initChargeItemFavorites(), this.initChargeItemFavoriteCategorys(), n])
        }, n.prototype.initCurChargeItemFavorites = function() {
            var n = this;
            this.$scope.chargeItemFavoriteCategory && (this.$scope.curChargeItemFavorites = this.$scope.chargeItemFavoriteList.filter(function(t) {
                return t.categoryId == n.$scope.chargeItemFavoriteCategory.id
            }), this.$scope.curChargeItemFavorites.forEach(function(t) {
                t.chargeItem = _.find(n.$scope.srcChargeItems, function(n) {
                    return t.chargeItemId == n.id
                })
            }))
        }, n.prototype.constructTreeData = function(n) {
            var t = this;
            (this.$scope.treeControl = new this.aresTreeControlUtil.TreeControl(n, [], {
                leafParentIdFieldName: "categoryId",
                leafItemNameSource: "name"
            }), this.$scope.treeControl) && (this.$scope.expandedNodes = [], this.$scope.treeData = this.$scope.treeControl.getTree(), this.$timeout(function() {
                t.$scope.expandedNodes.push(t.$scope.treeData[0])
            }))
        }, n.prototype.onSelecteTree = function(n) {
            this.$scope.chargeItemFavoriteCategory && n.id == this.$scope.chargeItemFavoriteCategory.id ? (this.$scope.hasSelected = !1, this.$scope.chargeItemFavoriteCategory = null) : (this.$scope.hasSelected = !0, this.$scope.chargeItemFavoriteCategory = n);
            this.initCurChargeItemFavorites()
        }, n.prototype.onOperationTree = function(n, t) {
            switch (t) {
                case 1:
                    this.editChargeItemFavoriteCategory(n);
                    break;
                case 2:
                    this.addChargeItemFavoriteCategory(n);
                    break;
                case 3:
                    break;
                case 4:
                    this.deleteChargeItemFavoriteCategory(n);
                    break;
                default:
                    return
            }
        }, n.prototype.addChargeItemFavoriteCategory = function(n) {
            var t = this,
                i = this.$modal.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-charge-item-favorite-edit-view><\/practice-charge-item-favorite-edit-view>",
                    windowClass: "membership-discountplan-detail-dialog",
                    controller: "PracticeChargeItemFavoriteEditCtrl",
                    resolve: {
                        host: function() {
                            return {
                                category: {
                                    parentId: n.id
                                },
                                categoryList: t.$scope.chargeItemFavoriteCategoryList,
                                parentCategory: n
                            }
                        }
                    }
                });
            i.result.then(function(n) {
                n && (n.itemName = n.name, t.$scope.treeControl.addBranch(n), t.aresNotification.success("添加成功"), t.initChargeItemFavoriteCategorys(!0))
            })
        }, n.prototype.editChargeItemFavoriteCategory = function(n) {
            var t = this,
                i = _.find(this.$scope.chargeItemFavoriteCategoryList, function(t) {
                    return n.parentId == t.id
                }),
                r = this.$modal.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-charge-item-favorite-edit-view><\/practice-charge-item-favorite-edit-view>",
                    windowClass: "membership-discountplan-detail-dialog",
                    controller: "PracticeChargeItemFavoriteEditCtrl",
                    resolve: {
                        host: function() {
                            return {
                                category: n,
                                categoryList: t.$scope.chargeItemFavoriteCategoryList,
                                parentCategory: i
                            }
                        }
                    }
                });
            r.result.then(function(n) {
                n && (n.itemName = n.name, t.$scope.treeControl.updateBranch(n), t.aresNotification.success("更新成功"))
            })
        }, n.prototype.deleteChargeItemFavoriteCategory = function(n) {
            var t = this;
            this.aresConfirmDialog.confirm({
                message: "确定要删除此类别？"
            }).then(function() {
                t.chargeItemSvc.deleteChargeItemFavoriteCategory(n.id).success(function() {
                    t.$scope.treeControl.deleteBranch(n);
                    t.$scope.curChargeItemFavorites = [];
                    t.aresNotification.success("删除成功");
                    t.initChargeItemFavoriteCategorys(!0)
                })
            })
        }, n.prototype.addChargeItemFavorites = function() {
            var n = this,
                t = this.$scope.curChargeItemFavorites.map(function(n) {
                    return n.chargeItem
                }),
                i = this.$modal.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-txplan-item-plan-view><\/practice-txplan-item-plan-view>",
                    controller: "PracticeTxplanItemPlanCtrl",
                    windowClass: "membership-discountplan-detail-dialog",
                    resolve: {
                        host: function() {
                            return {
                                chargeItemList: t,
                                chargeItemFilterMethod: function(n) {
                                    return _.filter(n, function(n) {
                                        return n.chargeItemType == 0
                                    })
                                }
                            }
                        }
                    }
                });
            i.result.then(function(t) {
                var i = t.map(function(n) {
                    return n.id
                });
                n.chargeItemSvc.updateChargeItemsByCategoryId(i, n.$scope.chargeItemFavoriteCategory.id).success(function() {
                    n.initChargeItemFavorites(!0).then(function() {
                        n.initCurChargeItemFavorites()
                    })
                })
            })
        }, n.prototype.deleteChargeItemFavorite = function(n) {
            var t = this;
            this.aresConfirmDialog.confirm({
                message: "确定要删除此套餐？"
            }).then(function() {
                t.chargeItemSvc.deleteChargeItemFavorite(n).success(function() {
                    t.aresNotification.success("删除成功");
                    t.initChargeItemFavorites(!0).then(function() {
                        t.initCurChargeItemFavorites()
                    })
                })
            })
        }, n.$inject = ["$log", "$q", "$scope", "$timeout", "chargeItemSvc", "dataDicSvc", "permissionProvider", "aresTreeControlUtil", "$modal", "aresNotification", "aresConfirmDialog", "loginContext"], n
    }();
    n.PracticeChargeItemFavoriteCtrl = t;
    chargeModule.controller("PracticeChargeItemFavoriteCtrl", Ares.tsController(t))
})(charge || (charge = {}));
practiceModule.controller("PracticeChargeItemFreeFieldCtrl", ["$log", "$q", "$scope", "$modal", "aresDialog", "practiceSvc", "dataDicSvc", "loginContext", "aresNotification", "officeSvc", "systemSettingItemSvc", "enums", "permissionProvider", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    var v = function() {
            i.freeFieldDicts = {};
            var n = e.chargeItemFreeFieldDic.load().then(function(n) {
                    i.freeFields = _.sortBy(n, "displayOrder");
                    i.freeFields.forEach(function(n) {
                        n.abbr = n.itemName + "选项"
                    })
                }),
                r = e.chargeItemFreeField1ItemDic.load().then(function(n) {
                    i.freeFieldDicts["收费项目自由项1选项"] = _.sortBy(n, "displayOrder")
                }),
                u = e.chargeItemFreeField2ItemDic.load().then(function(n) {
                    i.freeFieldDicts["收费项目自由项2选项"] = _.sortBy(n, "displayOrder")
                }),
                f = e.chargeItemFreeField3ItemDic.load().then(function(n) {
                    i.freeFieldDicts["收费项目自由项3选项"] = _.sortBy(n, "displayOrder")
                }),
                o = function() {
                    var n = l.BaseDataCategory,
                        t = n.ChargeItem;
                    e.officeBaseDataOptionDic.load().then(function(n) {
                        var r = _.find(n, function(n) {
                            return n.category == t
                        });
                        i.chargeItemAboutEnabled = r && r.isParentEnabled ? !1 : !0
                    })
                };
            return t.all([o(), n, r, u, f])
        },
        y = function(n) {
            n === "收费项目自由项1选项" ? e.chargeItemFreeField1ItemDic.clearCache() : n === "收费项目自由项2选项" ? e.chargeItemFreeField2ItemDic.clearCache() : n === "收费项目自由项3选项" && e.chargeItemFreeField3ItemDic.clearCache()
        },
        p = function(n, r) {
            var u = t.defer(),
                f, e, o;
            return r && r.trim().length > 20 ? (u.reject({
                msg: "项目名称不能超过20个字符"
            }), u.promise) : _.some(i.freeFieldDicts[n], function(n) {
                return n.itemName === r
            }) ? (u.reject({
                msg: "已经有其他项目使用此名称，请更换新名称！"
            }), u.promise) : (i.freeFieldDicts[n] && i.freeFieldDicts[n].length !== 0 ? (e = _.max(i.freeFieldDicts[n], function(n) {
                return n.displayOrder
            }), f = e.displayOrder + 1) : f = 1, o = {
                id: 0,
                itemName: r,
                itemType: n,
                itemTypeName: "收费项目自由项",
                displayOrder: f
            }, c.createSystemSettingItem(o).success(function() {
                y(n);
                v();
                u.resolve(!0)
            }).error(function(n) {
                u.reject(n)
            }), u.promise)
        },
        w = function(n) {
            var t = i.selectedItem[n],
                u, f;
            t && (u = _.find(i.freeFields, function(t) {
                return n === t.abbr
            }), f = r.open({
                animation: !0,
                backdrop: "static",
                template: "<system-setting-item-edit-dialog-view><\/system-setting-item-edit-dialog-view>",
                controller: "SystemSettingItemEditDialogCtrl",
                size: "sm",
                resolve: {
                    host: function() {
                        return {
                            systemsettingId: t.id,
                            parentCatagoryId: -1,
                            siblings: i.freeFieldDicts[n],
                            dataTypeName: u.itemValue,
                            currentSystemItem: angular.copy(i.selectedItem[n])
                        }
                    }
                }
            }), f.result.then(function() {
                y(n);
                v()
            }))
        },
        b = function(n) {
            var t = i.selectedItem[n];
            t && u.confirm("提示", "确定要删除此配置？").then(function() {
                c.deleteSystemSettingItem(t.id).success(function() {
                    s.success("删除成功！");
                    y(n);
                    v()
                }).error(function(n) {
                    if (n.name === "SystemItemUsedException") {
                        var i = t.itemName;
                        u.warn("提示", "【" + i + "】已被产品使用,不能删除！");
                        return
                    }
                    u.warn("信息", "删除失败")
                })
            })
        },
        k = function(n) {
            c.updateSystemSettingItemList(i.freeFieldDicts[n]).success(function() {
                y(n);
                s.success("排序保存成功！")
            })
        };
    (function() {
        i.initSystemItems = v;
        i.newItemName = {};
        i.selectedItem = {};
        i.addItem = p;
        i.deleteItem = b;
        i.editItem = w;
        i.updateList = k;
        i.isChargeItemEditAllowed = a.isChargeItemEditAllowed
    })()
}]);

practiceModule.controller("PracticeChargePackageCategoryEditCtrl", ["$log", "$q", "$scope", "$timeout", "dataDicSvc", "$modalInstance", "host", "aresNotification", "chargeSvc", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var c = function() {
            f.dismiss("close")
        },
        h = function(n) {
            f.close(n)
        },
        l = function() {
            i.category.id || (i.category.name = "")
        },
        a = function(n, t) {
            return t.some(function(t) {
                return t == n
            })
        },
        v = function() {
            var n = i.category.name.trim(),
                t;
            if (!n) return o.error("类目名称不能为空！"), !1;
            if (t = i.categoryList.filter(function(n) {
                    return n.id != i.category.id && i.category.id
                }).map(function(n) {
                    return n.name.trim()
                }), a(n, t)) return o.error("类目名称已被使用！"), !1;
            s.saveChargePackageCategory(i.category).then(function(n) {
                var t = n.data;
                o.success("保持成功");
                h(t)
            })
        };
    (function() {
        i.category = e.category;
        i.categoryList = e.categoryList;
        i.cancel = c;
        i.close = h;
        i.save = v;
        l()
    })()
}]);
practiceModule.controller("PracticeChargePackageCategoryMoveCtrl", ["$log", "$scope", "$http", "$state", "$modalInstance", "aresDialog", "chargeSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    t.cancel = function() {
        u.dismiss("cancel")
    };
    var s = function(n) {
            e.moveChargePackge(n.id, n.categoryId).success(function(n) {
                u.close(n)
            })
        },
        h = {
            showActionBar: !1,
            showLeafs: !1
        };
    (function() {
        t.chargePackage = o.chargePackage;
        t.treeControl = o.treeControl;
        t.treeData = t.treeControl.getTree();
        t.categoryNames = t.treeControl.getBranchBreadcrumbById(t.chargePackage.categoryId);
        t.treeOpts = h;
        t.movePackage = s
    })()
}]);
practiceModule.controller("PracticeChargePackageEditCtrl", ["$log", "$scope", "$q", "$modal", "aresDialog", "practiceSvc", "chargeSvc", "dataDicSvc", "aresNotification", "permissionProvider", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    var a = function() {
            return i.all([o.chargeItemDic.load().then(function(n) {
                t.chargeItems = n
            }), o.chargeCategoryDic.load().then(function(n) {
                t.categoryItems = n
            }), o.chargeSuperCategoryDic.load().then(function(n) {
                t.superCategoryItems = n
            }), ])
        },
        v = function() {
            t.isDialog || t.$watch("chargePackage", function() {
                l()
            })
        },
        l = function() {
            var n, u, i, r;
            if (t.chargePackage && t.chargePackage.id)
                for (t.title = "编辑收费组合", n = t.chargePackage, n.chargeItemList = [], n.diagnoseItem = [], u = 0; u < n.items.length; u++) i = n.items[u], r = _.find(t.chargeItems, function(n) {
                    return n.id == i.chargeItemId
                }), r && (i.chargeItem = {
                    id: r.id,
                    itemName: r.itemName,
                    unit: r.unit,
                    count: i.count,
                    price: i.price
                }, n.chargeItemList.push(i.chargeItem));
            else t.title = "新建收费组合", t.chargePackage = t.chargePackage || {}, angular.extend(t.chargePackage, {
                namr: "",
                code: "",
                totalPrice: 0,
                displayOrder: t.displayOrder,
                items: []
            })
        },
        y = function() {
            var n = r.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-txplan-item-plan-view><\/practice-txplan-item-plan-view>",
                controller: "PracticeTxplanItemPlanCtrl",
                windowClass: "membership-discountplan-detail-dialog",
                resolve: {
                    host: function() {
                        return {
                            chargeItemList: t.chargePackage.chargeItemList,
                            chargeItemFilterMethod: function(n) {
                                return _.filter(n, function(n) {
                                    return n.chargeItemType == 0
                                })
                            }
                        }
                    }
                }
            });
            n.result.then(function(n) {
                n && (t.chargePackage.chargeItemList = n, c(t.chargePackage.chargeItemList))
            })
        },
        c = function(n) {
            t.chargePackage.totalPrice = 0;
            for (var i = 0; i < n.length; i++) t.chargePackage.totalPrice += Ares.priceToFixed(n[i].price * n[i].count), n.totalPrice = Ares.priceToFixed(n[i].price * n[i].count)
        },
        p = function(n) {
            t.chargePackage.chargeItemList.splice(n, 1);
            c(t.chargePackage.chargeItemList)
        },
        w = function(n, i) {
            var u = n.sender,
                r = u.value();
            r == null && (u.value(1), t.chargePackage.chargeItemList[i].count = 1, r = 1);
            t.chargePackage.chargeItemList[i].count = r;
            c(t.chargePackage.chargeItemList)
        },
        b = function(n, i) {
            var u = n.sender,
                r = u.value();
            r == null && (u.value(1), t.chargePackage.chargeItemList[i].price = 1, r = 1);
            t.chargePackage.chargeItemList[i].price = r;
            c(t.chargePackage.chargeItemList)
        },
        k = function(n, i) {
            var r = t.chargePackages.filter(function(t) {
                    return t.name == n
                }),
                u = t.chargeItems.filter(function(t) {
                    return t.itemName == n
                }),
                f = t.categoryItems.filter(function(t) {
                    return t.itemName == n
                }),
                e = t.superCategoryItems.filter(function(t) {
                    return t.itemName == n
                });
            return i && (r = r.filter(function(n) {
                return n.id != i
            })), r.length == 0 && u.length == 0 && f.length === 0 && e.length === 0
        },
        d = function() {
            if (!t.chargePackage.name) return s.error("项目名称不能为空!"), !1;
            if (!k(t.chargePackage.name, t.chargePackage.id)) return s.error("项目名称已被使用!"), !1;
            t.save()
        },
        g = function() {
            var i, n, r;
            if (t.chargePackage.items = [], t.chargePackage.categoryId = t.chargePackage.categoryId > 0 ? t.chargePackage.categoryId : null, t.chargePackage.chargeItemList)
                for (i = 0; i < t.chargePackage.chargeItemList.length; i++) n = t.chargePackage.chargeItemList[i], r = Ares.priceToFixed(n.price * n.count), t.chargePackage.items.push({
                    chargePackageId: t.chargePackage.id,
                    chargeItemId: n.id,
                    count: n.count,
                    price: n.price,
                    totalPrice: Ares.priceToFixed(n.count * n.price)
                });
            t.chargePackage.id > 0 ? nt() : e.createChargePackage(t.chargePackage).success(function(n) {
                n && (o.chargePackageDic.clearCache(), n.categoryId || (n.categoryId = 0), t.close ? t.close(n) : s.success("创建成功"))
            }).error(function(n) {
                n.name === "PackageCodeException" && u.warn("提示", "该项目代码已经存在！")
            })
        },
        nt = function() {
            t.chargePackage.categoryId = t.chargePackage.categoryId > 0 ? t.chargePackage.categoryId : null;
            e.updateChargePackage(t.chargePackage).success(function(n) {
                n && (o.chargePackageDic.clearCache(), n.categoryId || (n.categoryId = 0), t.close ? t.close(n) : s.success("更新成功"))
            }).error(function(n) {
                n.name === "PackageCodeException" && u.warn("提示", "该项目代码已经存在！")
            })
        };
    (function() {
        t.addChargeItem = y;
        t.deleteChargeItem = p;
        t.saveCheck = d;
        t.fixPrice = Ares.priceToFixed;
        t.save = g;
        t.onItemCountChange = w;
        t.onItemPriceChange = b;
        t.isChargeItemEditAllowed = h.isChargeItemEditAllowed;
        a().then(function() {
            l();
            v()
        })
    })()
}]);
practiceModule.controller("PracticeChargePackageCtrl", ["$log", "$scope", "$q", "$timeout", "$window", "$modal", "$http", "aresDialog", "enums", "practiceSvc", "chargeSvc", "loginContext", "aresTreeControlUtil", "dataDicSvc", "aresNotification", "permissionProvider", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p) {
    "use strict";
    var g = function() {
            var n = i.defer(),
                r = s.BaseDataCategory,
                u = r.ChargeItem;
            return v.officeBaseDataOptionDic.load().then(function(i) {
                var r = _.find(i, function(n) {
                    return n.category == u
                });
                t.chargeItemAboutEnabled = r && r.isParentEnabled ? !1 : !0;
                n.resolve()
            }), n.promise
        },
        nt = function() {
            t.treeOpts = {
                addLeafBtnTitle: "添加收费套餐",
                showActionBar: p.isChargeItemEditAllowed
            };
            var n = v.chargePackageDic.load().then(function(n) {
                    for (var i, u = 0, r = 0; r < n.length; r++) i = n[r], i.index = r + 1, (i.displayOrder == null || i.displayOrder != u) && (i.displayOrder = u), i.categoryId || (i.categoryId = 0), i.cate && u++;
                    t.chargePackageList = n
                }),
                r = v.chargePackageCategoryDic.load().then(function(n) {
                    for (var i, u = 0, f = [{
                            name: "收费套餐",
                            parentId: 0,
                            id: 0,
                            ownerId: null
                        }].concat(n), r = 0; r < f.length; r++) i = f[r], i.index = r + 1, (i.displayOrder == null || i.displayOrder != u) && (i.displayOrder = u), i.itemName = i.name, u++;
                    t.chargePackageCategoryList = f
                });
            return t.isDialog = !1, i.all([g(), n, r])
        },
        tt = function(n, i) {
            (t.treeControl = new a.TreeControl(n, i, {
                leafParentIdFieldName: "categoryId",
                leafItemNameSource: "name"
            }), t.treeControl) && (t.expandedNodes = [], t.treeData = t.treeControl.getTree(), r(function() {
                t.expandedNodes.push(t.treeData[0])
            }))
        },
        it = function(n) {
            t.hasSelected || (t.hasSelected = !0);
            t.selectedChagePackage = n
        },
        rt = function(n, t) {
            switch (t) {
                case 1:
                    n.level ? ft(n) : k(n);
                    break;
                case 2:
                    ut(n);
                    break;
                case 3:
                    b(n);
                    break;
                case 4:
                    n.level ? et(n) : d(n);
                    break;
                default:
                    return
            }
        },
        w = function() {
            return t.chargeItemAboutEnabled ? !0 : (o.warn("提示", "没有权限修改收费套餐配置"), !1)
        },
        ut = function(n) {
            if (w()) {
                var i = f.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-charge-package-category-edit-view ><\/practice-charge-package-category-edit-view>",
                    windowClass: "membership-discountplan-detail-dialog",
                    controller: "PracticeChargePackageCategoryEditCtrl",
                    resolve: {
                        host: function() {
                            return {
                                category: {
                                    parentId: n.id
                                },
                                categoryList: t.chargePackageCategoryList
                            }
                        }
                    }
                });
                i.result.then(function(n) {
                    n && (n.itemName = n.name, t.treeControl.addBranch(n), y.success("添加成功"), v.chargePackageCategoryDic.clearCache())
                })
            }
        },
        ft = function(n) {
            if (w()) {
                var i = f.open({
                    animation: !0,
                    backdrop: "static",
                    template: "<practice-charge-package-category-edit-view ><\/practice-charge-package-category-edit-view>",
                    windowClass: "membership-discountplan-detail-dialog",
                    controller: "PracticeChargePackageCategoryEditCtrl",
                    resolve: {
                        host: function() {
                            return {
                                category: n,
                                categoryList: t.chargePackageCategoryList
                            }
                        }
                    }
                });
                i.result.then(function(n) {
                    n && (n.itemName = n.name, t.treeControl.updateBranch(n), y.success("更新成功"), v.chargePackageCategoryDic.clearCache())
                })
            }
        },
        et = function(n) {
            w() && o.confirm("提示", "确定要删除此套餐？").then(function() {
                c.deleteChargePackageCategory(n.id).success(function() {
                    t.treeControl.deleteBranch(n);
                    y.success("删除成功");
                    v.chargePackageCategoryDic.clearCache()
                })
            })
        },
        b = function(n) {
            if (w()) {
                var i = t,
                    r = f.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-charge-package-edit-view charge-package='chargePackage'                                                              display-order='chargePackageList.length'                                                              charge-packages='chargePackageList'                                                              is-dialog='dialog'                                                              close='cancel'><\/practice-charge-package-edit-view>",
                        windowClass: "membership-discountplan-detail-dialog",
                        controller: ["$scope", "$modalInstance", function(t, r) {
                            t.cancel = function(n) {
                                r.close(n)
                            };
                            t.dialog = !0;
                            t.chargePackage = {
                                categoryId: n.id
                            };
                            t.chargePackageList = i.chargePackageList
                        }]
                    });
                r.result.then(function(n) {
                    n && (n.categoryId = n.categoryId || 0, t.treeControl.addLeaf(n), y.success("添加成功"), v.chargePackageDic.clearCache())
                })
            }
        },
        k = function(n) {
            if (w()) {
                var i = t,
                    r = f.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-charge-package-edit-view charge-package='chargePackage'                                                              display-order='chargePackageList.length'                                                              charge-packages='chargePackageList'                                                              is-dialog='dialog'                                                              close='cancel'><\/practice-charge-package-edit-view>",
                        controller: ["$scope", "$modalInstance", function(t, r) {
                            t.cancel = function() {
                                r.close()
                            };
                            t.dialog = !0;
                            t.chargePackage = n;
                            t.chargePackageList = i.chargePackageList
                        }],
                        windowClass: "membership-discountplan-detail-dialog"
                    });
                r.result.then(function(n) {
                    n && (n.categoryId = n.categoryId || 0, t.treeControl.updateLeaf(n), y.success("更新成功"), v.chargePackageDic.clearCache())
                })
            }
        },
        ot = function(n) {
            var i = f.open({
                animation: !0,
                backdrop: "static",
                template: "<practice-charge-package-category-move-view><\/practice-charge-package-category-move-view>",
                controller: "PracticeChargePackageCategoryMoveCtrl",
                windowClass: "charge-package-move-wrap",
                resolve: {
                    host: function() {
                        return {
                            chargePackage: n,
                            treeControl: t.treeControl
                        }
                    }
                }
            });
            i.result.then(function(n) {
                n.categoryId = n.categoryId || 0;
                t.treeControl.moveLeaf(n);
                t.selectedChagePackage.categoryId = n.categoryId;
                v.chargePackageDic.clearCache()
            })
        },
        d = function(n) {
            w() && o.confirm("提示", "确定要删除此套餐？").then(function() {
                c.deleteChargePackage(n.id).success(function(i) {
                    i && (t.treeControl.deleteLeaf(n), y.success("删除成功"), v.chargePackageDic.clearCache())
                })
            })
        },
        st = function(n, i) {
            var r, f, u, e;
            t.isDisableDbClick = !0;
            r = t.chargePackageList[i.displayOrder];
            f = i.displayOrder;
            t.chargePackageList.splice(i.displayOrder, 1, t.chargePackageList[n.displayOrder]);
            t.chargePackageList.splice(n.displayOrder, 1, r);
            u = n.displayOrder;
            e = n.index;
            t.chargePackageList[i.displayOrder].displayOrder = r.displayOrder;
            t.chargePackageList[u].displayOrder = u;
            t.chargePackageList[f].index = r.index;
            t.chargePackageList[u].index = e;
            c.updateChargePackages(t.chargePackageList).success(function() {
                t.refreshUpDownGrid(f);
                t.isDisableDbClick = !1
            })
        },
        ht = function(n, i) {
            var r, f, u, e;
            t.isDisableDbClick = !0;
            r = t.chargePackageList[n.displayOrder];
            f = n.displayOrder;
            t.chargePackageList.splice(n.displayOrder, 1, t.chargePackageList[i.displayOrder]);
            t.chargePackageList.splice(i.displayOrder, 1, r);
            u = i.displayOrder;
            e = i.index;
            t.chargePackageList[n.displayOrder].displayOrder = r.displayOrder;
            t.chargePackageList[u].displayOrder = u;
            t.chargePackageList[f].index = r.index;
            t.chargePackageList[u].index = e;
            c.updateChargePackages(t.chargePackageList).success(function() {
                t.refreshDownGrid(f);
                t.isDisableDbClick = !1
            })
        };
    (function() {
        t.onSelecteTree = it;
        t.onOperationTree = rt;
        t.isDisableDbClick = !1;
        t.upItem = st;
        t.downItem = ht;
        t.moveChargePackage = ot;
        t.addChargePackage = b;
        t.editChargePackage = k;
        t.deleteChargePackage = d;
        t.chargePackageList = {};
        nt().then(function() {
            tt(t.chargePackageCategoryList, t.chargePackageList)
        })
    })()
}]);
practiceModule.controller("PracticeChargeSuperCategoryEditCtrl", ["$q", "$scope", "officeSvc", "chargeItemSvc", "$modalInstance", "host", "loginContext", "dataDicSvc", function(n, t, i, r, u, f, e, o) {
    "use strict";
    var s = function() {
            u.dismiss("close")
        },
        h = function(t) {
            var i = n.defer(),
                f;
            return f = t.id > 0 ? r.updateChargeItemSuperCategory({
                id: t.id,
                itemName: t.itemName,
                itemEnglishName: t.itemEnglishName,
                syncOptions: t.syncOptions
            }) : r.createChargeItemSuperCategory({
                itemName: t.itemName,
                itemEnglishName: t.itemEnglishName,
                syncOptions: t.syncOptions,
                displayOrder: t.displayOrder
            }), f.success(function(n) {
                o.chargeItemDic.refresh();
                u.close(n);
                i.resolve()
            }).error(function() {
                i.reject()
            }), i.promise
        },
        c = function() {
            var t = n.defer(),
                r = e.officeId;
            return i.getOfficeNodesByParent(r).success(function(n) {
                var i = n.filter(function(n) {
                    return n.bizType == 1
                });
                t.resolve(i)
            }), t.promise
        },
        l = function() {
            var i = n.defer();
            return r.getSyncInfo("ChargeItemSuperCategory", t.superCategory.id).success(function(n) {
                i.resolve(n)
            }), i.promise
        };
    (function() {
        t.checkNewItemNameUnique = f.checkNewItemNameUnique;
        t.superCategory = f.superCategory;
        t.close = s;
        t.save = h;
        t.getOrganizationInfo = c;
        t.getSuperCategorySyncOptions = l
    })()
}]);
practiceModule.controller("PracticeChargeItemBrowserCtrl", ["$log", "$q", "$scope", "$location", "$window", "$modal", "$http", "sessionCache", "aresDialog", "followupSvc", "practiceSvc", "dataDicSvc", "officeOptionSvc", "enums", "loginContext", "aresNotification", "productSvc", "officeSvc", "permissionProvider", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k) {
    "use strict";
    var tt = function(n) {
            n.allowDiscountStr = n.allowDiscount == null || n.allowDiscount == undefined || n.allowDiscount ? "是" : "否"
        },
        it = function(n) {
            n = parseInt(n);
            var t = [];
            t = n ? i.srcCatagoryItems.filter(function(t) {
                return t.itemSuperCategoryId == n
            }) : i.srcCatagoryItems;
            i.currentSelectCategoryTreeData ? i.currentSelectCategoryTreeData.data(t) : i.currentSelectCategoryTreeData = new kendo.data.HierarchicalDataSource({
                data: t
            })
        },
        g = function() {
            var n, u, r;
            return i.currentCategoryChargeItems = [], i.currentCategoryItem ? (u = 0, r = i.currentCategoryItem.id, i.currentCategoryChargeItems = i.srcChargeItems.filter(function(n) {
                return i.isProductSaleEnabled ? n.itemCatagoryId == r : n.itemCatagoryId == r && n.chargeItemType != 1
            }), i.currentCategoryChargeItems.forEach(function(n) {
                tt(n)
            }), ut(i.currentCategoryChargeItems)) : (n = t.defer(), rt(), n.resolve(), n.promise)
        },
        rt = function() {
            i.allChargeItems = [];
            var n = 0;
            i.srcCatagoryItems.forEach(function(t) {
                var r = i.srcChargeItems.filter(function(n) {
                    return n.itemCatagoryId == t.id
                });
                r = _.sortBy(r, function(n) {
                    return n.displayOrder
                });
                r.forEach(function(r) {
                    r.itemType = t.itemName;
                    r.index = n + 1;
                    i.allChargeItems.push(r);
                    n++
                })
            });
            i.allChargeItems.forEach(function(n) {
                tt(n)
            })
        },
        ut = function(n) {
            var u = t.defer(),
                r, f;
            if (!n || n.length == 0) return u.resolve(n), u.promise;
            var e = _.pluck(n, "displayOrder"),
                o = _.uniq(e).length == e.length,
                s = n.some(function(n) {
                    var t = parseFloat(n.displayOrder);
                    return t != 0 && !t
                });
            for (n = !o || s ? _.sortBy(n, function(n) {
                    return n.id
                }) : _.sortBy(n, function(n) {
                    return n.displayOrder
                }), r = 0; r < n.length; r++) f = n[r], f.index = r + 1, f.displayOrder = r;
            return !o || s ? c.updateChargeItemList(n).then(function() {
                return d(!0)
            }).then(function() {
                u.resolve(n)
            }) : u.resolve(n), u.promise.then(function(n) {
                return i.currentCategoryChargeItems = n, n
            })
        },
        st = function() {
            return l.chargePackageDic.load().then(function(n) {
                i.chargePackages = n
            })
        },
        d = function(n) {
            return n && l.chargeItemDic.clearCache(), l.chargeItemDic.load().then(function(n) {
                i.srcChargeItems = [];
                i.hasSaleItem && (i.srcChargeItems = i.srcChargeItems.concat(n.filter(function(n) {
                    return n.chargeItemType === 1
                })));
                i.hasCommonItem && (i.srcChargeItems = i.srcChargeItems.concat(n.filter(function(n) {
                    return n.chargeItemType === 0 || n.chargeItemType === 3 || n.chargeItemType === 4 || n.chargeItemType === 5 || n.chargeItemType === 6
                })))
            })
        },
        ht = function() {
            return l.chargeCategoryDic.load().then(function(n) {
                i.totalCategoryItems = n;
                var t = n;
                i.srcCatagoryItems = [];
                i.srcSuperCategoryItems.forEach(function(n) {
                    var r = t.filter(function(t) {
                        return t.itemSuperCategoryId == n.id
                    });
                    r = _.sortBy(r, function(n) {
                        return n.displayOrder
                    });
                    i.srcCatagoryItems = i.srcCatagoryItems.concat(r)
                })
            })
        },
        ct = function() {
            return l.chargeSuperCategoryDic.load().then(function(n) {
                i.srcSuperCategoryItems = [{
                    id: 0,
                    itemName: "全部"
                }];
                n = _.sortBy(n, function(n) {
                    return n.displayOrder
                });
                i.hasSaleItem || (n = n.filter(function(n) {
                    return n.itemName !== "库存商品销售"
                }));
                i.srcSuperCategoryItems = i.srcSuperCategoryItems.concat(n)
            })
        },
        lt = function() {
            var n = t.defer();
            return h.getRuleLites().then(function(t) {
                i.followupRuleLites = t.data;
                n.resolve()
            }), n.promise
        },
        at = function() {
            var n = t.defer();
            return l.officeSettingDic.load().then(function(t) {
                i.isProductSaleEnabled = t.isInventoryProductSaleEnabled;
                n.resolve()
            }), n.promise
        },
        vt = function() {
            return at().then(function() {
                return t.all([lt(), ct(), ht(), d(!1), st()])
            }).then(function() {
                i.superCatagoryId = 0;
                it(i.superCatagoryId)
            })
        },
        ft = function(n) {
            var t = _.sortBy(n, function(n) {
                return n.displayOrder
            });
            return i.currentCategoryChargeItems[t[0].displayOrder]
        },
        et = function(n) {
            var t = n.length,
                r = _.sortBy(n, function(n) {
                    return n.displayOrder
                });
            return i.currentCategoryChargeItems[r[t - 1].displayOrder]
        },
        ot = function(n) {
            n.forEach(function(n) {
                var t = _.findIndex(i.currentCategoryChargeItems, function(t) {
                    return t.id == n.id
                });
                n.displayOrder = null;
                i.currentCategoryChargeItems.splice(t, 1)
            })
        },
        yt = function(n) {
            var u = ft(n).displayOrder,
                t, r;
            return ot(n), t = [u - 1, 0], t = t.concat(n), [].splice.apply(i.currentCategoryChargeItems, t), r = [], i.currentCategoryChargeItems.forEach(function(n, t) {
                n.index = t + 1;
                n.displayOrder != t && (n.displayOrder = t, r.push(n))
            }), nt(r, !0)
        },
        pt = function(n) {
            var f = et(n).displayOrder,
                u, t, r;
            return ot(n), u = f + 1 - n.length + 1, t = [u, 0], t = t.concat(n), [].splice.apply(i.currentCategoryChargeItems, t), r = [], i.currentCategoryChargeItems.forEach(function(n, t) {
                n.index = t + 1;
                n.displayOrder != t && (n.displayOrder = t, r.push(n))
            }), nt(r, !0)
        },
        wt = function(n) {
            c.updateChargeItem(n).success(function() {
                l.chargeItemDic.clearCache();
                d(!0).then(function() {
                    return g()
                }).then(function() {
                    i.refreshCurrentCategoryChargeItemsGridData()
                })
            }).error(function() {
                s.warn("信息", "编辑失败")
            })
        },
        kt = function() {},
        nt = function(n, r) {
            var u = t.defer();
            return c.updateChargeItemList(n).success(function(n) {
                if (r) {
                    l.chargeItemDic.refreshItemsEx(n);
                    var t = _.sortBy(l.chargeItemDic.data(), "displayOrder");
                    l.chargeItemDic.setCache(t);
                    i.refreshCurrentCategoryChargeItemsGridData();
                    u.resolve()
                } else l.chargeItemDic.clearCache(), p.success("更新成功！"), d(!0).then(function() {
                    return g()
                }).then(function() {
                    i.refreshCurrentCategoryChargeItemsGridData();
                    u.resolve()
                })
            }).error(function() {
                p.error("信息", "更新失败");
                u.reject()
            }), u.promise
        },
        bt = function() {
            i.isYibaoItemPriceUpdatable = !1;
            i.isYibaoGatewayEnabled = !1;
            i.gatewatYibaoItems = null;
            a.getOfficeOption(a.optionKeys.IsYibaoItemPriceUpdatable).then(function(n) {
                i.isYibaoItemPriceUpdatable = n
            });
            a.getOfficeOption(a.optionKeys.IsYibaoGatewayEnabled).then(function(n) {
                i.isYibaoGatewayEnabled = n;
                n && l.insuranceMateDataDic.load().then(function(n) {
                    var r = o.getCache(o.keys.YibaoUseChannel).loadValue(),
                        t;
                    n && n.length > 0 && (t = _.find(n, function(n) {
                        return n.type == v.GatewayChannelType.Yibao && n.name == r
                    }), t && (i.gatewatYibaoItems = t.chargeItems))
                })
            })
        };
    (function() {
        i.hasSaleItem = !0;
        i.hasCommonItem = !0;
        i.currentCategory = null;
        i.initData = vt;
        i.setAllChargeItems = rt;
        i.updateChargeItems = nt;
        i.setChargeItemsSortOrderPromise = ut;
        i.setCurrentSelectCategoryTreeData = it;
        i.setCurrentCategoryChargeItemsPromise = g;
        i.upChargeItems = yt;
        i.downChargeItems = pt;
        i.getSortFirstChargeItem = ft;
        i.getSortLastChargeItem = et;
        i.udpateChargeItem = wt;
        i.initChargeItems = d;
        i.isChargeItemEditAllowed = k.isChargeItemEditAllowed;
        bt()
    })()
}]);
practiceModule.controller("PracticeChargeItemCategoryEditCtrl", ["$log", "$q", "$scope", "$modalInstance", "host", function(n, t, i, r, u) {
    "use strict";
    var f = function() {
            s().then(function(n) {
                var t = _.find(i.canSelectCategoryItems, function(n) {
                    return n.id == i.newCategoryItemId
                });
                i.selectedChargeItems.forEach(function(r) {
                    r.displayOrder = n;
                    r.itemCatagoryId = i.newCategoryItemId;
                    r.itemSuperCategoryId = t.itemSuperCategoryId;
                    n++
                });
                r.close(i.selectedChargeItems)
            })
        },
        e = function() {
            r.dismiss()
        },
        o = function() {
            i.hasChangeCategory = i.selectedChargeItems[0].itemCatagoryId != i.newCategoryItemId
        },
        s = function() {
            var n = i.srcChargeItems.filter(function(n) {
                return n.itemCatagoryId == i.newCategoryItemId
            });
            return i.setCategoryItemSortMethod(n).then(function(t) {
                n = t;
                return n.length > 0 ? _.max(n, function(n) {
                    return n.displayOrder
                }).displayOrder + 1 : 0
            })
        };
    (function() {
        i.hasChangeCategory = !1;
        i.oldCategoryItem = u.oldCategoryItem;
        i.canSelectCategoryItems = u.canSelectCategoryItems;
        i.selectedChargeItems = u.selectedChargeItems;
        i.srcChargeItems = u.srcChargeItems;
        i.setCategoryItemSortMethod = u.setCategoryItemSortMethod;
        i.save = f;
        i.close = e;
        i.changeChargeItemCategory = o;
        i.newCategoryItemId = i.oldCategoryItem.id;
        i.oldCategoryItemName = i.oldCategoryItem.itemName;
        i.selectedChargeItemLength = i.selectedChargeItems.length
    })()
}]);
practiceModule.controller("PracticeChargeItemEditCtrl", ["$log", "$scope", "$location", "$modalInstance", "$http", "$sce", "$state", "$q", "aresDialog", "appNav", "practiceSvc", "moduleOptionProvider", "dataDicSvc", "enums", "constants", "loginContext", "host", "systemSettingItemSvc", "membershipSvc", "aresNotification", "deductionSvc", "systemConfigUtil", "chargeItemSvc", "productSvc", "officeOptionSvc", "productUnitySvc", "officeSvc", "permissionProvider", "apptApplyCompleteUtil", function(n, t, i, r, u, f, e, o, s, h, c, l, a, v, y, p, w, b, k, d, g, nt, tt, it, rt, ut, ft, et, ot) {
    "use strict";
    var ct;
    t.currentChargeItem = {};
    t.currentChargeItemCatagory = {};
    t.subChargeTypeList = {};
    t.hasChangeCategroy = !1;
    t.origionChargeItem = {};
    t.currentProduct = null;
    t.cancel = function() {
        r.dismiss("cancel")
    };
    ct = function(n, i) {
        var f = t.chargePackages.filter(function(t) {
                return t.name === n
            }),
            u = [];
        t.hasChildOrgs && t.syncOptions && (u = t.syncOptions.allowSyncOrganizations);
        var r = t.chargeItems.filter(function(i) {
                var r = [];
                return t.hasChildOrgs && i.allowSyncOrganizations && i.allowSyncOrganizations.length > 0 && (r = i.allowSyncOrganizations.filter(function(n) {
                    return !n.isExcluded
                }).map(function(n) {
                    return n.targeOrganizationId
                })), i.itemName === n ? t.hasChildOrgs ? u.some(function(n) {
                    return r.some(function(t) {
                        return n == t
                    })
                }) ? !0 : !1 : !0 : !1
            }),
            e = t.srcCategoryItems.filter(function(t) {
                return t.itemName === n
            }),
            o = t.superCategoryItems.filter(function(t) {
                return t.itemName === n
            });
        return i && (r = r.filter(function(n) {
            return n.id != i
        })), f.length === 0 && r.length === 0 && e.length === 0 && o.length === 0
    };
    t.saveChargeItem = function() {
        var r, i, n;
        if (t.currentChargeItem.chargeItemType == 0) {
            if (!vt()) return;
            lt();
            t.currentChargeItem.productId = null
        } else if (t.currentChargeItem.chargeItemType == 1) {
            if (!yt()) return;
            pt()
        }
        hi();
        a.chargeItemDic.load();
        ui();
        r = a.chargeItemDic.data();
        t.currentChargeItem.id ? (i = t.currentChargeItem.itemName, n = _.find(r, function(n) {
            return n.id == t.currentChargeItem.id
        }), i === n.itemName && t.currentChargeItem.itemType == n.itemType ? n.allowDiscount && n.allowDiscount != t.currentChargeItem.allowDiscount ? k.valChargeItem(i).success(function(n) {
            var t, i;
            if (n && n.length > 0) {
                for (t = "", i = 0; i < n.length; i++) t = t + '"' + n[i].name + '",';
                t = t.substring(0, t.length - 1);
                s.confirm("提示", f.trustAsHtml("以下优惠方案使用了此收费项目,修改为不允许打折后原优惠方案将继续生效。<\/br>" + t + '<\/br><span style="margin-left:40px;">您确认要修改为“否”吗<\/span>')).then(function() {
                    st()
                })
            } else st()
        }) : st() : st()) : bt();
        t.chargeItems = a.chargeItemDic.data()
    };
    var vt = function() {
            var f = t.currentChargeItem.itemName,
                n, i, r, u;
            if (!ct(f, t.currentChargeItem.id)) return d.error("收费项目名称已被使用！"), !1;
            if (!t.currentCategory) return d.error("收费项目所属小类不能为空！"), !1;
            if (t.allowChargeDeduction && t.currentChargeItem.isDeductionEnabled && !t.currentChargeItem.isAutoDeduct && (!t.currentDeductionPlan || !t.currentDeductionPlan.id)) return d.error("划扣方案不能为空！"), !1;
            if (t.currentChargeItem.isDeductionEnabled)
                for (n = 0; n < t.currentChargeItem.deductionSteps.length; n++)
                    if (i = t.currentChargeItem.deductionSteps[n].stepProducts, i)
                        for (r = 0; r < i.length; r++)
                            if (u = i[r].defaultCount, !u || u <= 0) return d.error("默认使用数量应填写大于0的整数且不能为空！"), !1;
            return !0
        },
        lt = function() {
            t.hasChangeCategroy = !t.currentChargeItem.id || t.currentChargeItem.itemCatagoryId != t.currentCategory.id;
            t.currentChargeItem.itemCatagoryId = t.currentCategory.id;
            t.currentChargeItem.itemCatagoryName = "";
            t.currentChargeItem.itemSuperCategoryId = t.currentSuperCategory ? t.currentSuperCategory.id : 0;
            t.currentChargeItem.itemSuperCategoryName = "";
            t.currentChargeItem.chargeDeductionPlanId = t.currentDeductionPlan && t.currentChargeItem.isDeductionEnabled ? t.currentDeductionPlan.id : 0
        },
        yt = function() {
            return t.currentChargeItem.product == null ? (d.error("请选择商品！"), !1) : !0
        },
        pt = function() {
            var n = t.currentChargeItem.product.product;
            lt();
            angular.extend(t.currentChargeItem, {
                itemName: t.currentChargeItem.productItemName,
                unit: n.unit,
                chargeItemType: 1,
                productId: n.id,
                isDeductionEnabled: !1,
                chargeDeductionPlanId: null,
                deductionSteps: []
            })
        },
        wt = function(n) {
            return t.chargeItems.filter(function(t) {
                return t.itemCatagoryId == n
            })
        },
        at = function() {
            if (t.hasChangeCategroy) {
                var n = wt(t.currentChargeItem.itemCatagoryId),
                    i = n.length > 0 ? _.max(n, function(n) {
                        return n.displayOrder
                    }).displayOrder + 1 : 0;
                t.currentChargeItem.displayOrder = i
            }
        },
        st = function() {
            at();
            c.updateChargeItem(t.currentChargeItem).success(function() {
                d.success("保存成功！");
                a.chargeItemDic.refresh();
                r.close(t.currentChargeItem)
            }).error(function() {})
        },
        bt = function() {
            at();
            c.createChargeItem(t.currentChargeItem).success(function() {
                d.success("创建成功！");
                a.chargeItemDic.refresh();
                r.close(t.currentChargeItem)
            }).error(function() {})
        },
        kt = function() {
            t.productList = []
        },
        dt = function() {
            t.syncOptions = {
                allowSyncOrganizations: []
            };
            t.popWindowTitle = w.chargeitemId > 0 ? "编辑收费项目" : "新增收费项目";
            t.chargeItems = a.chargeItemDic.data();
            t.catagoryId = w.catagoryId;
            t.chargeitemId = w.chargeitemId;
            t.displayOrder = w.chargedisplayOrder;
            t.srcCategoryItems = w.categoryItems;
            t.superCategoryItems = w.superCategoryItems;
            t.chargePackages = w.chargePackages;
            t.followupRuleLites = w.followupRuleLites;
            t.isNewChargeItem = w.chargeitemId == undefined;
            t.isShowAllowUpdatePrice = w.isYibaoGatewayEnabled && w.isGatewayYibaoItem && w.isYibaoItemPriceUpdatable;
            a.officeSettingDic.load().then(function(n) {
                t.isConnectYongyouHrp = n.isConnectYonyouHrp;
                t.isProductSaleEnabled = n.isInventoryProductSaleEnabled;
                t.allowChargeDeduction = n.isDeductionChargeEnabled;
                t.isConnectYongyouHrp && kt()
            });
            t.currentCategory = _.find(t.srcCategoryItems, function(n) {
                return n.id == t.catagoryId
            });
            t.currentSuperCategory = _.find(t.superCategoryItems, function(n) {
                return n.id == t.currentCategory.itemSuperCategoryId
            });
            t.categoryItems = t.srcCategoryItems.filter(function(n) {
                return n.itemSuperCategoryId == t.currentSuperCategory.id
            });
            rt.getOfficeOption(rt.optionKeys.BaseDataConfig).then(function(n) {
                var i = JSON.parse(n);
                t.procedureCodeRequired = i.chargeItemRequired.procedureCode
            });
            var n = p.officeId;
            ei(n)
        },
        ht = function(n) {
            return function(i) {
                var s = !0,
                    f, e, u, r, o;
                if (!i) return s;
                for (f = a.chargeItemDic.data(), e = [], t.hasChildOrgs && t.syncOptions && (e = t.syncOptions.allowSyncOrganizations), u = 0; u < f.length; ++u)
                    if (r = f[u], o = [], t.hasChildOrgs && r.allowSyncOrganizations && r.allowSyncOrganizations.length > 0 && (o = r.allowSyncOrganizations.filter(function(n) {
                            return !n.isExcluded
                        }).map(function(n) {
                            return n.targeOrganizationId
                        })), r[n] == i)
                        if (t.currentChargeItem.id == r.id) continue;
                        else if (t.hasChildOrgs) {
                    if (e.some(function(n) {
                            return o.some(function(t) {
                                return n == t
                            })
                        })) return !1;
                    continue
                } else return !1;
                return s
            }
        },
        gt = function() {
            var n = jQuery;
            n.validator.addMethod("chargeItemCode", ht("procedureCode"), "编码已被使用！");
            n.validator.addMethod("chargeItemName", ht("itemName"), "名称已被使用！");
            n.validator.addMethod("chargeItemEnglishName", ht("itemEnglishName"), "英文名称已被使用！")
        },
        ni = function(n) {
            var r, f, u, i, e;
            if (t.currentChargeItem.chargeDeductionPlanId = n, t.currentChargeItem.isDeductionEnabled = n && n > 0 ? !0 : !1, t.origionChargeItem.chargeDeductionPlanId == n) t.currentChargeItem.deductionSteps = angular.copy(t.origionChargeItem.deductionSteps);
            else if (n == 0) t.currentChargeItem.deductionSteps = [], t.currentDeductionPlan = null;
            else if (r = _.find(t.deductionPlanList, function(t) {
                    return t.id == n
                }), t.currentDeductionPlan = r, f = [], r && r.steps) {
                for (u = 0; u < r.steps.length; u++) i = r.steps[u], e = {
                    chargeItemId: t.currentChargeItem.id,
                    stepName: i.stepName,
                    stepRatio: i.stepRatio,
                    stepIndex: i.stepIndex,
                    manHourCount: i.manHourCount,
                    isRepeatable: i.isRepeatable,
                    defaultRepeatCount: i.defaultRepeatCount,
                    isAllowSkip: i.isAllowSkip,
                    isNeedApprove: i.isNeedApprove,
                    syncSourceId: i.syncSourceId,
                    followupRuleId: i.followupRuleId,
                    isAutoExecute: i.isAutoExecute,
                    planStepId: i.id,
                    stepProducts: []
                }, f.push(e);
                t.currentChargeItem.deductionSteps = f
            }
        },
        ti = function() {
            var i = o.defer(),
                n;
            return t.chargeitemId > 0 ? (n = _.find(t.chargeItems, function(n) {
                return n.id == t.chargeitemId
            }), n.minDiscount = n.minDiscount ? n.minDiscount : 0, n.minPrice = n.minPrice ? n.minPrice : 0, n.maxPrice = n.maxPrice ? n.maxPrice : 999999, t.origionChargeItem = angular.copy(n), t.currentChargeItem = angular.copy(n), t.currentChargeItem.allowDiscount = t.currentChargeItem.allowDiscount == null || t.currentChargeItem.allowDiscount == !0 ? !0 : !1, t.currentChargeItem.allowOrderDiscount = t.currentChargeItem.allowOrderDiscount == null || t.currentChargeItem.allowOrderDiscount == !0 ? !0 : !1, t.currentChargeItem.itemSuperCategoryId || (t.currentChargeItem.itemSuperCategoryId = t.currentSuperCategory.id), n.chargeItemType == 1 && n.productId ? ut.getByProductId(n.productId, !0).then(function(r) {
                var u = _.filter(r.products, function(t) {
                        return t.id == n.productId
                    }),
                    f = {};
                u && u.length > 0 && (f = u[0]);
                t.currentChargeItem.product = {
                    productUnity: r,
                    product: f
                };
                t.srcProduct = t.currentChargeItem.product;
                t.currentProductId = n.productId;
                i.resolve()
            }) : i.resolve()) : (t.currentChargeItem = {
                id: 0,
                itemName: "",
                procedureCode: "",
                itemCatagoryId: t.catagoryId,
                itemCatagoryName: t.currentCategory.itemName,
                itemSuperCategoryId: t.currentSuperCategory.id,
                itemSuperCategoryName: t.currentSuperCategory.Name,
                allowDiscount: !0,
                allowOrderDiscount: !0,
                displayOrder: t.displayOrder,
                isDeductionEnabled: !1,
                deductionSteps: [],
                chargeItemType: 0,
                minDiscount: 0,
                minPrice: 0,
                maxPrice: 999999
            }, i.resolve()), i.promise
        },
        ii = function() {
            var n = o.defer();
            return a.systemsettingDic.load().then(function(i) {
                t.subChargeTypeList = [""];
                for (var r = 0; r < i.length; ++r) i[r].itemType == "费用类型" && t.subChargeTypeList.push(i[r].itemName);
                n.resolve()
            }), n.promise
        },
        ri = function() {
            var n = o.defer();
            return g.getPlanList().success(function(i) {
                t.deductionPlanList = [{
                    deductionType: 0,
                    id: 0,
                    planName: "无"
                }];
                i && i.length > 0 && (t.deductionPlanList = t.deductionPlanList.concat(i));
                t.currentDeductionPlan = t.currentChargeItem.chargeDeductionPlanId ? _.find(t.deductionPlanList, function(n) {
                    return n.id == t.currentChargeItem.chargeDeductionPlanId
                }) : t.deductionPlanList[0];
                n.resolve()
            }), n.promise
        },
        ui = function() {
            var n = t.currentChargeItem.freeFieldInfo;
            n.field1 = n["收费项目自由项1选项"];
            n.field2 = n["收费项目自由项2选项"];
            n.field3 = n["收费项目自由项3选项"]
        },
        fi = function() {
            var n;
            t.freeFieldDicts = {};
            n = {};
            n["收费项目自由项1选项"] = "";
            n["收费项目自由项2选项"] = "";
            n["收费项目自由项3选项"] = "";
            t.currentChargeItem.freeFieldInfo = n;
            var r = a.chargeItemFreeFieldDic.load().then(function(n) {
                    t.freeFields = _.sortBy(n, "displayOrder");
                    t.freeFields.forEach(function(n) {
                        n.abbr = n.itemName + "选项"
                    })
                }),
                u = a.chargeItemFreeField1ItemDic.load().then(function(n) {
                    t.freeFieldDicts["收费项目自由项1选项"] = _.sortBy(n, "displayOrder")
                }),
                f = a.chargeItemFreeField2ItemDic.load().then(function(n) {
                    t.freeFieldDicts["收费项目自由项2选项"] = _.sortBy(n, "displayOrder")
                }),
                e = a.chargeItemFreeField3ItemDic.load().then(function(n) {
                    t.freeFieldDicts["收费项目自由项3选项"] = _.sortBy(n, "displayOrder")
                }),
                i = [r, u, f, e];
            return t.currentChargeItem.id > 0 && i.push(b.getChargeItemFreeFieldValue(t.currentChargeItem.id).then(function(n) {
                n.data && (t.currentChargeItem.freeFieldInfo["收费项目自由项1选项"] = n.data.field1, t.currentChargeItem.freeFieldInfo["收费项目自由项2选项"] = n.data.field2, t.currentChargeItem.freeFieldInfo["收费项目自由项3选项"] = n.data.field3)
            })), o.all(i)
        },
        ei = function(n) {
            ft.getOfficeNodesByParent(n).success(function(n) {
                var i = n.filter(function(n) {
                    return n.bizType == 1
                });
                t.hasChildOrgs = i && i.length > 0;
                t.orgInfoData = i;
                oi().then(function(n) {
                    t.syncOptions.allowSyncOrganizations = _.uniq(n);
                    t.hasChildOrgs && t.$watch("syncOptions.allowSyncOrganizations", function(n) {
                        n && t.currentChargeItem.itemName && t.valid()
                    })
                })
            })
        },
        oi = function() {
            var n = o.defer();
            return tt.getSyncInfo("ChargeItem", t.currentChargeItem.id).then(function(i) {
                var r, u, f;
                t.currentChargeItem.allowSyncOrganizations = i.data;
                r = t.currentChargeItem.allowSyncOrganizations;
                u = "";
                u = r && r.length != 0 ? r.filter(function(n) {
                    return !n.isExcluded
                }).map(function(n) {
                    return n.targeOrganizationId
                }) : t.orgInfoData.map(function(n) {
                    return n.id
                });
                r && r.length > 0 && (f = si(r), f && f.length > 0 && f.forEach(function(n) {
                    u.push(n)
                }));
                n.resolve(u)
            }), n.promise
        },
        si = function(n) {
            for (var r = [], u = n.map(function(n) {
                    return n.targeOrganizationId
                }), i = 0; i < t.orgInfoData.length; i++) u.indexOf(t.orgInfoData[i].id) == -1 && r.push(t.orgInfoData[i].id);
            return r
        },
        hi = function() {
            var n = [],
                i = t.syncOptions.allowSyncOrganizations;
            t.orgInfoData.forEach(function(t) {
                var r = i.indexOf(t.id) == -1;
                n.push({
                    targeOrganizationId: t.id,
                    isExcluded: r
                })
            });
            t.currentChargeItem.allowSyncOrganizations = n
        },
        ci = function(n) {
            var r = n.sender,
                i = r.value();
            i < t.currentChargeItem.minPrice && (t.currentChargeItem.minPrice = i);
            i > t.currentChargeItem.maxPrice && (t.currentChargeItem.maxPrice = i)
        },
        li = function() {
            var n = {
                chargeItemId: t.currentChargeItem.id,
                stepName: "自动执行划扣",
                stepRatio: 100,
                stepIndex: 1,
                manHourCount: null,
                isRepeatable: !1,
                defaultRepeatCount: null,
                isAllowSkip: !1,
                isNeedApprove: !1,
                syncSourceId: null,
                followupRuleId: null,
                isAutoExecute: !0,
                stepProducts: []
            };
            t.currentChargeItem.deductionSteps = [];
            t.currentChargeItem.deductionSteps.push(n)
        },
        ai = function() {
            var n = o.defer();
            return nt.getConfigValue(nt.configKeys.IsShowAutoDeductionExecuteSwitchEnabled).then(function(i) {
                t.isShowAutoDeductionExecuteSwitchEnabled = i;
                n.resolve()
            }), n.promise
        },
        vi = function() {
            a.officeBaseDataOptionDic.load().then(function(n) {
                var i = _.find(n, function(n) {
                    return n.category == 1
                });
                t.isParentEnabled = i && i.isParentEnabled
            })
        },
        yi = function() {
            t.currentChargeItem.itemSuperCategoryName != y.ValueAddSuperCategoryName && (t.superCategoryItems = t.superCategoryItems.filter(function(n) {
                return n.itemName != y.ValueAddSuperCategoryName
            }))
        },
        pi = function() {
            rt.isSelfOrChildOfficeOpened(rt.optionKeys.IsHealthBureauDataExportEnabled, p.officeId).then(function(n) {
                t.isHealthBureauDataExportEnabled = n
            });
            rt.isSelfOrChildOfficeOpened(rt.optionKeys.IsHealthBureauDataExportEnabled_Shenzhen, p.officeId).then(function(n) {
                t.IsHealthBureauDataExportEnabled_Shenzhen = n
            })
        },
        wi = function(n, t) {
            return n & t
        },
        bi = function(n) {
            return ot.isCompleteItemType(n.chargeItemType)
        };
    (function() {
        gt();
        dt();
        t.createAutoDeductDeductionStep = li;
        t.chargeDeductionPlanSelected = ni;
        t.getCurrentChargeItem = ti;
        t.getSubChargeTypeList = ii;
        t.getDeductionPlan = ri;
        t.getFreeFieldInfo = fi;
        t.onPriceChanged = ci;
        t.getBaseConfig = ai;
        t.getBaseData = vi;
        t.filterAlipaybpCategory = yi;
        t.isChargeItemEditAllowed = et.isChargeItemEditAllowed;
        t.isYouzanEnabled = l.isYouzanEnabled();
        t.bitwiseAnd = wi;
        t.isServiceAddChargeItem = bi;
        pi()
    })()
}]);
practiceModule.controller("PracticeChargeitemProductEditCtrl", ["$log", "$scope", "$location", "$http", "$timeout", "$sce", "$state", "$q", "productUnitySvc", "dataDicSvc", "productCategoriesUtil", "aresTreeViewUtil", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var y = function() {
            p().then(function() {
                a().then(function(n) {
                    t.productUnityList = n
                })
            })
        },
        p = function() {
            var n = o.defer();
            return c.getProductCategories().then(function(i) {
                t.selCategoryId = 0;
                t.selCategory = {
                    name: "所属类目",
                    id: 0
                };
                t.categoriesTree = l.unflatten(i, "showOrder");
                t.categoriesTree.splice(0, 0, t.selCategory);
                n.resolve(!0)
            }), n.promise
        },
        a = function(n) {
            var r = o.defer(),
                u, i;
            return n && n === t.pageCount ? r.resolve(t.productUnityList) : (n = n ? n + 1 : 1, u = t.categoryId ? [t.categoryId] : null, i = {
                pageIndex: n,
                pageSize: 5,
                categoriesIds: u,
                dealerId: 0,
                searchText: t.searchKeywords,
                isWithProducts: !0,
                isWithProductSumCount: !0,
                isEnabled: !0
            }, i.category === "所属类目" && (i.category = null), s.search(i).success(function(n) {
                var i = n.items;
                v().then(function(u) {
                    i.forEach(function(n, t, i) {
                        if (i[t].products && i[t].products.length > 0) {
                            var r = i[t].products;
                            r.forEach(function(n, t, i) {
                                var r = _.filter(u, function(n) {
                                    return i[t].id === n
                                });
                                i[t].isAdded = r && r > 0
                            })
                        }
                    });
                    t.productUnityList || (t.productUnityList = []);
                    var f = t.productUnityList.concat(n.items);
                    t.pageIndex = n.pageIndex;
                    t.pageCount = n.pageCount;
                    r.resolve(f)
                })
            })), r.promise
        },
        v = function() {
            var n = o.defer(),
                t = [];
            return h.chargeItemDic.loadActive({
                chargeItemType: 1
            }).then(function(i) {
                i && i.length > 0 && i.forEach(function(n, i, r) {
                    t.push(r[i].productId)
                });
                n.resolve(t)
            }), n.promise
        },
        w = function(n, i) {
            u(function() {
                if (!i.isAdded) {
                    var r = {
                        productUnity: n,
                        product: i
                    };
                    t.addProduct(r);
                    i.isAdded = !0;
                    t.currentProductId && t.currentProductId > 0 && t.productUnityList.forEach(function(n) {
                        n.products && n.products.length > 0 && n.products.forEach(function(n) {
                            n.id === t.currentProductId && (n.isAdded = !1)
                        })
                    });
                    t.currentProductId = i.id
                }
            })
        },
        b = function() {
            v().then(function(n) {
                t.productUnityList.forEach(function(t, i, r) {
                    if (r[i].products && r[i].products.length > 0) {
                        var u = r[i].products;
                        u.forEach(function(t, i, r) {
                            var u = _.filter(n, function(n) {
                                return r[i].id === n
                            });
                            r[i].isAdded = u && u > 0
                        })
                    }
                })
            })
        };
    (function() {
        t.search = a;
        t.selectProduct = w;
        t.initSelectProductStatus = b;
        y()
    })()
}]);
practiceModule.controller("EmrTemplateComponentConfigCtrl", ["$log", "$scope", "$q", "practiceSvc", "loginContext", "appNav", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            var n = i.defer();
            return t.archives ? n.resolve(t.archives) : r.getArchive().success(function(i) {
                t.archives = i;
                n.resolve(i)
            }), n.promise
        },
        o = function() {
            u.isRoot || f.goToState("setting.emr.config")
        };
    (function() {
        t.getArchive = e;
        o()
    })()
}]);
practiceModule.controller("EmrTemplateConfigCtrl", ["$log", "$scope", "$q", "practiceSvc", "loginContext", "appNav", function(n, t, i, r, u, f) {
    "use strict";
    var e = function() {
            var n = i.defer();
            return t.archives ? n.resolve(t.archives) : r.getArchive().success(function(i) {
                t.archives = i;
                n.resolve(i)
            }), n.promise
        },
        o = function() {
            u.isRoot || f.goToState("setting.emr.config")
        };
    (function() {
        t.getArchive = e;
        o()
    })()
}]);
practiceModule.controller("EmrTemplatePreviewCtrl", ["$log", "$scope", "$q", "$modalInstance", "host", function(n, t, i, r, u) {
    "use strict";
    var f = function() {
            r.dismiss("close")
        },
        e = function() {
            u.layoutTemplate ? (t.layoutTemplate = u.layoutTemplate, t.title = u.layoutTemplate.templateName) : (t.layoutTemplate = {
                rootFields: [u.layoutField]
            }, t.title = u.layoutField.fieldName);
            t.allowEditToothFDI = !0;
            t.currentMedicalRecord = {
                isShowChiefComplaint: !0,
                isShowHistory: !0,
                isShowPastHistory: !0,
                isShowOralCheckRecordList: !0,
                oralCheckRecordList: [{
                    fdiToothCodesArray: []
                }],
                isShowRadiologyCheckRecordList: !0,
                radiologyCheckRecordList: [{
                    fdiToothCodesArray: []
                }],
                isShowDiagnoseRecordList: !0,
                diagnoseRecordList: [{
                    fdiToothCodesArray: []
                }],
                isShowTreatmentAdviceList: !0,
                treatmentAdviceList: [{
                    fdiToothCodesArray: []
                }],
                isShowTreatmentPlanList: !0,
                treatmentPlanList: [{
                    fdiToothCodesArray: []
                }],
                isShowCureRecordList: !0,
                cureRecordList: [{
                    fdiToothCodesArray: []
                }],
                isShowAdvice: !0
            }
        };
    (function() {
        t.cancel = f;
        e()
    })()
}]);
practiceModule.controller("PracticePaymentTypeBaseCtrl", ["$log", "$q", "$scope", "$injector", "dataDicSvc", "paymentTypeSvc", "enums", "aresNotification", "aresDialog", "aresModalShelf", "moduleUtil", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    var a = function() {
            i.isUpgradeUnstart ? b() : k()
        },
        b = function() {
            var n = t.defer();
            return u.paymentTypeDic.load().then(function(t) {
                i.paymentTypes = angular.copy(t);
                i.paymentTypeCategories = [];
                v();
                y();
                l();
                n.resolve()
            }), n.promise
        },
        k = function() {
            var n = t.defer(),
                r = u.paymentTypeDic.load().then(function(n) {
                    i.paymentTypes = angular.copy(n)
                }),
                f = u.paymentTypeCategoryDic.load().then(function(n) {
                    i.paymentTypeCategories = n
                });
            return t.all([r, f]).then(function() {
                v();
                y();
                p();
                l();
                w();
                n.resolve()
            }), n.promise
        },
        v = function() {
            d();
            i.integratePaytypeNames = ["汇付/小白盒/微信", "汇付/小白盒/支付宝", "汇付/小白盒/云闪付", "汇付/扫一扫/微信", "汇付/扫一扫/支付宝", "汇付/扫一扫/云闪付", "汇付/银行卡", "银联/小白盒/微信", "银联/小白盒/支付宝", "银联/小白盒/云闪付", "银联/Pos"]
        },
        d = function() {
            var t = _.find(i.paymentTypeCategories, function(n) {
                    return n.name == "支付优惠"
                }),
                n = t ? t.id : 0;
            i.splitPaymentTypeData = [{
                parentName: "预付款",
                splits: [{
                    name: "储值卡本金",
                    categoryId: null
                }, {
                    name: "储值卡馈赠金",
                    categoryId: n
                }]
            }, {
                parentName: "现金券",
                splits: [{
                    name: "现金券本金",
                    categoryId: null
                }, {
                    name: "现金券馈赠金",
                    categoryId: n
                }]
            }, {
                parentName: "不记名卡",
                splits: [{
                    name: "不记名卡本金",
                    categoryId: null
                }, {
                    name: "不记名卡馈赠金",
                    categoryId: n
                }]
            }, {
                parentName: "汇付/小白盒",
                splits: [{
                    name: "汇付/小白盒/微信",
                    categoryId: null
                }, {
                    name: "汇付/小白盒/支付宝",
                    categoryId: null
                }, {
                    name: "汇付/小白盒/云闪付",
                    categoryId: null
                }]
            }, {
                parentName: "银联/小白盒",
                splits: [{
                    name: "银联/小白盒/微信",
                    categoryId: null
                }, {
                    name: "银联/小白盒/支付宝",
                    categoryId: null
                }, {
                    name: "银联/小白盒/云闪付",
                    categoryId: null
                }]
            }, {
                parentName: "汇付/扫一扫",
                splits: [{
                    name: "汇付/扫一扫/微信",
                    categoryId: null
                }, {
                    name: "汇付/扫一扫/支付宝",
                    categoryId: null
                }, {
                    name: "汇付/扫一扫/云闪付",
                    categoryId: null
                }]
            }, {
                parentName: "支付宝标品",
                splits: [{
                    name: "支付宝标品采购价",
                    categoryId: null
                }, {
                    name: "支付宝标品优惠",
                    categoryId: n
                }]
            }, {
                parentName: "微医保",
                splits: [{
                    name: "微医保采购价",
                    categoryId: null
                }, {
                    name: "微医保优惠",
                    categoryId: n
                }]
            }, {
                parentName: "天猫拼多多",
                splits: [{
                    name: "天猫拼多多采购价",
                    categoryId: null
                }, {
                    name: "天猫拼多多优惠",
                    categoryId: n
                }]
            }, {
                parentName: "京东健康",
                splits: [{
                    name: "京东健康采购价",
                    categoryId: null
                }, {
                    name: "京东健康优惠",
                    categoryId: n
                }]
            }]
        },
        y = function() {
            for (var f, r, o, n, t, u = 0; u < i.splitPaymentTypeData.length; u++)
                if (f = i.splitPaymentTypeData[u], r = i.paymentTypes.findIndex(function(n) {
                        var t = n.name == f.parentName;
                        return n.name == "预付款" && (t = t && n.isDefault), t
                    }), r > -1) {
                    var e = i.paymentTypes[r],
                        s = e.paymentTypeConfigs,
                        h = e.newPaymentTypeConfigs;
                    for (o = f.splits.length - 1; o >= 0; o--) n = f.splits[o], t = angular.copy(e), t.name = n.name, t.categoryId = n.categoryId ? n.categoryId : e.categoryId, t.paymentTypeConfigs = s.filter(function(t) {
                        return t.name == n.name
                    }), t.newPaymentTypeConfigs = h.filter(function(t) {
                        return t.name == n.name
                    }), i.paymentTypes.splice(r + 1, 0, t);
                    i.paymentTypes.splice(r, 1)
                }
        },
        p = function() {
            for (var t, r, u = _.groupBy(i.paymentTypes, function(n) {
                    return n.categoryId
                }), n = 0; n < i.paymentTypeCategories.length; n++) i.paymentTypeCategories[n].isShowPaymentTypes = !0, t = i.paymentTypeCategories[n].id, r = u[t], i.paymentTypeCategories[n].paymentTypes = r;
            i.unknownPaymentTypes = i.paymentTypes.filter(function(n) {
                return !n.categoryId
            });
            i.isForceNewReportEnabled && g()
        },
        w = function() {
            var n = _.find(i.paymentTypeCategories, function(n) {
                    return n.name == "现金类实收"
                }),
                t;
            n && n.paymentTypes && n.paymentTypes.length != 0 && (t = n.paymentTypes.filter(function(n) {
                return i.integratePaytypeNames.indexOf(n.name) >= 0
            }), t && t.length > 0 && (i.integratePayTypeCategory = {
                isShow: !0,
                isExpand: !0,
                paymentTypes: t
            }))
        },
        g = function() {
            if (i.unknownPaymentTypes && i.unknownPaymentTypes.length != 0) {
                var n = _.find(i.paymentTypeCategories, function(n) {
                    return n.name == "现金类实收"
                });
                n && (n.paymentTypes || (n.paymentTypes = []), i.unknownPaymentTypes.forEach(function(t) {
                    t.warnNotes = "自定义";
                    t.categoryId = n.id;
                    t.isDefaultUpgrade = !0;
                    t.originName = t.name;
                    n.paymentTypes.push(t)
                }))
            }
        },
        l = function() {
            for (var n = 0; n < i.paymentTypeCategories.length; n++) {
                var r = i.paymentTypeCategories[n],
                    u = r.configs,
                    t = r.paymentTypes;
                if (t && t.length > 0) {
                    var f = _.find(u, function(n) {
                            return n.scenario == e.PaymentScenario.Charge
                        }),
                        o = _.find(u, function(n) {
                            return n.scenario == e.PaymentScenario.AdvancePayment
                        }),
                        s = f && f.isEnabled,
                        h = o && o.isEnabled;
                    t.forEach(function(n) {
                        n.isCommonChargeScenarioEnalbed = s;
                        n.isAdvanceChargeScenarioEnalbed = h
                    })
                }
            }
        },
        nt = function(n) {
            if (i.isEditEnabled(n, !0)) {
                var t = angular.copy(n);
                t.isDisabled = !t.isDisabled;
                t.originName = t.name;
                f.updatePaymentType(t).then(function() {
                    n.isDisabled = !n.isDisabled;
                    tt(n);
                    u.paymentTypeDic.clearCache()
                }, function() {
                    var t = n.isDisabled ? "启用" : "禁用";
                    o.error(t + "失败")
                })
            }
        },
        tt = function(n) {
            for (var t, e, r, f, u = 0; u < i.splitPaymentTypeData.length; u++)
                if (t = i.splitPaymentTypeData[u].splits, e = _.any(t, function(t) {
                        return t.name == n.name
                    }), e) {
                    for (r = 0; r < t.length; r++) t[r].name != n.name && (f = _.find(i.paymentTypes, function(n) {
                        return n.name == t[r].name
                    }), f && (f.isDisabled = n.isDisabled));
                    break
                }
        },
        it = function(n) {
            return n ? n.name ? !0 : (o.error("支付方式名称不能为空！"), !1) : (o.error("支付方式不能为空！"), !1)
        },
        rt = function(n) {
            return {
                displayOrder: n.displayOrder,
                id: n.id,
                isDefault: n.isDefault,
                isInactive: n.isInactive,
                code: n.code,
                originName: n.originName,
                name: n.name,
                itemType: n.itemType,
                itemValue: n.itemValue,
                oldId: n.oldId,
                pinyin: n.pinyin,
                recordCreatedTime: n.recordCreatedTime,
                notes: n.notes,
                incomeType: n.incomeType
            }
        },
        ut = function() {
            c.load("charge").then(function() {
                var n = r.get("chargeBasePayTypeUtil");
                i.defaultPaymentTypeNames = n.fullDefaultPaytypeNames
            });
            i.deleteInfoMsg = "支付方式删除后，已使用的收费单不受影响，新建收费时将不可使用， 确定要删除支付方式";
            i.forbiddenEnabledPaytypes = ["储值卡本金", "储值卡馈赠金", "不记名卡本金", "不记名卡馈赠金", "现金券本金", "现金券馈赠金", "支付宝标品采购价", "支付宝标品优惠", "微医保采购价", "微医保优惠", "天猫拼多多采购价", "天猫拼多多优惠", "京东健康采购价", "京东健康优惠", "团购券/大众点评", "医保", "商保", "泰康养老", "健保通", "特需金"]
        },
        ft = function(n) {
            return !n.isDefault && n.id > 0 && i.defaultPaymentTypeNames.indexOf(n.name) < 0 && i.isEditEnabled(n)
        },
        et = function() {
            a();
            ut()
        },
        ot = function(n) {
            var r = t.defer();
            return s.confirm("提示", i.deleteInfoMsg + "（" + n.name + "）？").then(function() {
                f.deleteNewPaymentType(n.id).then(function() {
                    u.paymentTypeDic.clearCache();
                    r.resolve()
                }, function(n) {
                    var t = n.data;
                    t.name == "PaymentTypeDeleteException" ? o.error(t.message) : o.error("删除失败");
                    r.reject()
                })
            }, function() {
                r.reject()
            }), r.promise
        },
        st = function(n, t, r) {
            var f = "",
                u = "",
                e;
            r ? (f = "查看类型说明", u = "info") : (f = t ? "编辑支付方式类型" : "新增支付方式类型", u = t ? "edit" : "create");
            e = h.open({
                template: "<payment-type-category-create-dialog-view><\/payment-type-category-create-dialog-view>",
                controller: "PaymentTypeCategoryCreateDialogCtrl",
                title: f,
                confirmClose: !1,
                resolve: {
                    host: function() {
                        return {
                            action: u,
                            category: t
                        }
                    }
                }
            });
            e.switchTab(0);
            e.result.then(function(n) {
                u == "create" ? (n.isShowPaymentTypes = !0, i.paymentTypeCategories.push(n)) : i.getPaymentTypes()
            })
        },
        ht = function(n) {
            var r = n ? n : {},
                f = n ? "编辑支付方式" : "新增支付方式",
                e = n ? "edit" : "create",
                t = h.open({
                    template: "<payment-type-create-dialog-view><\/payment-type-create-dialog-view>",
                    controller: "PaymentTypeCreateDialogCtrl",
                    title: f,
                    confirmClose: !1,
                    resolve: {
                        host: function() {
                            return {
                                paymentTypeCategories: i.paymentTypeCategories,
                                paymentType: r,
                                action: e,
                                allPaymentTypes: i.paymentTypes,
                                defaultPaymentTypeNames: i.defaultPaymentTypeNames
                            }
                        }
                    }
                });
            t.switchTab(0);
            t.result.then(function(n) {
                u.paymentTypeDic.clearCache();
                i.onPaymentTypeChanged(n)
            })
        },
        ct = function(n, t) {
            var f = _.findIndex(i.paymentTypes, function(t) {
                    return t.id == n.id
                }),
                r, u, e;
            if (t) {
                i.paymentTypes.splice(f, 1);
                return
            }
            if (f >= 0)
                if (r = i.paymentTypes.filter(function(t) {
                        return t.id == n.id
                    }), r && r.length == 1) i.paymentTypes.splice(f, 1, n);
                else
                    for (u = 0; u < r.length; u++) e = r[u], e.code = n.code, e.notes = n.notes;
            else i.paymentTypes.push(n)
        },
        lt = function(n, t) {
            ct(n, t);
            i.groupPyamentTypeByCategory();
            i.initPaymentTypeEnabled();
            w()
        };
    (function() {
        i.defaultPaymentTypeNames = [];
        i.getPaymentTypes = a;
        i.validatePaymentType = it;
        i.getPaymentTypeDto = rt;
        i.switchPaymentTypeEnabled = nt;
        i.isDeleteEnabled = ft;
        i.groupPyamentTypeByCategory = p;
        i.initPaymentTypeEnabled = l;
        i.deletePaymentTypePromise = ot;
        i.createOrEditPaymentTypeCategory = st;
        i.createOrEditPaymentType = ht;
        i.onPaymentTypeChanged = lt;
        i.splitPaymentTypeData = [];
        i.integratePaytypeNames = [];
        i.integratePayTypeCategory = {
            isShow: !1,
            isExpand: !1,
            paymentTypes: []
        };
        et()
    })()
}]);
practiceModule.controller("PracticePaymentTypeNewCtrl", ["$log", "$scope", "$q", "$controller", function(n, t, i, r) {
    var f = this,
        e = r("PracticePaymentTypeBaseCtrl", {
            $scope: t
        }),
        u;
    angular.extend(f, e);
    u = function() {
            t.isCreateCategoryEnabled = t.isUpgradeEnabled && (t.isUpgradeStart || t.isUpgradeComplete) && t.hasEditPermission && t.isCustomCategoryEnabled;
            t.isCreatePaymentTypeEanbled = t.isUpgradeComplete && t.hasEditPermission
        },
        function() {
            u()
        }()
}]);
practiceModule.controller("PracticePaymentTypeOldCtrl", ["$log", "$scope", "$q", "$state", "$controller", "moduleOptionProvider", "permissionProvider", "paymentTypeSvc", "dataDicSvc", "aresNotification", "enums", "officeOptionSvc", "appNav", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    var a = this,
        v = u("PracticePaymentTypeBaseCtrl", {
            $scope: t
        });
    angular.extend(a, v);
    var y = function() {
            p()
        },
        p = function() {
            t.isCreateEnabled = t.hasEditPermission && t.isUpgradeUnstart;
            t.isEditAllowed = t.hasEditPermission && (t.isUpgradeUnstart || t.isUpgradeComplete && !t.isNewPaymentTypeEnabled);
            t.isShowUpgradeHint = t.isUpgradeEnabled && !t.isUseParentChargeItem && !t.isUpgradeComplete && !t.isForceNewReportEnabled || t.isForceNewReportEnabled && t.isUpgradeUnstart && !t.isUseParentChargeItem
        },
        w = function(n) {
            var r = i.defer(),
                u;
            return t.validatePaymentType(n) ? (u = t.getPaymentTypeDto(n), o.updateNewPaymentType(u).then(function() {
                n.originName = n.name;
                n.paymentTypeConfigs[0].name = n.name;
                n.paymentTypeConfigs[1].name = n.name;
                n.paymentTypeConfigs[2].name = n.name;
                s.paymentTypeDic.clearCache();
                t.onCompletePaymentTypeEdit();
                r.resolve()
            }, function(n) {
                n.data && n.data.name == "SystemSettingItemNameNotUniqueException" ? h.error("已存在相同名称的支付方式！") : n.data && n.data.name == "SystemSettingItemCodeNotUniqueException" && h.error("已存在相同编码的支付方式！");
                r.reject()
            })) : r.reject(), r.promise
        },
        b = function(n) {
            var r = i.defer(),
                u;
            return n.originName = n.name, t.validatePaymentType(n) ? (u = t.getPaymentTypeDto(n), o.createNewPaymentType(u).success(function(i) {
                n.viewStatus = "show";
                t.onCompletePaymentTypeEdit();
                r.resolve(i)
            }).error(function() {
                r.reject()
            })) : r.reject(), r.promise
        },
        k = function(n) {
            var t = i.defer();
            return o.savePaymentTypeConfig(n).success(function(n) {
                s.paymentTypeDic.clearCache();
                t.resolve(n)
            }).error(function() {
                t.reject()
            }), t.promise
        },
        d = function() {
            g() && (t.isUpgradeStart || (t.isPaymentTypeUpgradeStart = !0, t.isUpgradeUnstart = !1, o.startUpgradePaymentType().then(function() {
                l.setOfficeOption(l.optionKeys.PaymentTypeUpgradeStatus, c.PaymentTypeUpgradeStatus.Started);
                l.refreshOfficeOption(l.optionKeys.PaymentTypeUpgradeStatus, c.PaymentTypeUpgradeStatus.Started);
                s.paymentTypeDic.clearCache();
                t.onUpgradeStart && _.isFunction(t.onUpgradeStart) && t.onUpgradeStart()
            })))
        },
        g = function() {
            return e.isPaymentTypeUpgradeAllowed ? !0 : (h.error("操作权限不足，请联系管理员进行操作"), !1)
        };
    (function() {
        t.updatePaymentTypePromise = w;
        t.savePaymentTypePromise = b;
        t.updatePaymentTypeConfigPromise = k;
        t.startUpgradePaymentTypes = d;
        y()
    })()
}]);
practiceModule.controller("PracticePaymentTypeUpgradeCtrl", ["$scope", "$q", "$controller", "enums", "dataDicSvc", "appNav", "paymentTypeSvc", "officeOptionSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var c = this,
        l = i("PracticePaymentTypeBaseCtrl", {
            $scope: n
        });
    angular.extend(c, l);
    var a = function() {
            var n = t.defer();
            return e.cancelUpgradePaymentType().then(function() {
                o.refreshOfficeOption(o.optionKeys.PaymentTypeUpgradeStatus, r.PaymentTypeUpgradeStatus.None);
                n.resolve()
            }, function() {
                n.reject()
            }), n.promise
        },
        v = function() {
            var t = n.unknownPaymentTypes.filter(function(n) {
                    return n.isUpgrade
                }),
                r, u, i, f;
            if (!t || t.length == 0) return 0;
            for (r = t.length - 1; r >= 0; r--) u = t[r], i = _.find(n.paymentTypeCategories, function(n) {
                return n.id == u.categoryId
            }), i && (i.paymentTypes || (i.paymentTypes = []), i.paymentTypes.push(u)), f = n.unknownPaymentTypes.indexOf(u), n.unknownPaymentTypes.splice(f, 1);
            return n.unknownPaymentTypes && n.unknownPaymentTypes.length != 0 || (n.isAllPaymentTypeUpgraded = !0), t.length
        },
        y = function() {
            return !n.unknownPaymentTypes || n.unknownPaymentTypes.length == 0
        },
        p = function() {
            u.paymentTypeDic.refresh()
        },
        h = function() {
            e.completeUpgradePaymentType().then(function() {
                o.refreshOfficeOption(o.optionKeys.PaymentTypeUpgradeStatus, r.PaymentTypeUpgradeStatus.Finished);
                o.refreshOfficeOption(o.optionKeys.IsNewPaymentTypeEnabled, !0);
                u.paymentTypeDic.clearCache();
                n.onUpgradeComplete && _.isFunction(n.onUpgradeComplete) && n.onUpgradeComplete()
            }, function() {})
        },
        w = function(n) {
            var i = t.defer();
            return e.deleteNewPaymentType(n.id).then(function() {
                b(n);
                u.paymentTypeDic.clearCache();
                i.resolve()
            }, function(n) {
                var t = n.data;
                t.name == "PaymentTypeDeleteException" ? s.error(t.message) : s.error("删除失败");
                i.reject()
            }), i.promise
        },
        b = function(t) {
            var r = n.paymentTypes.indexOf(t),
                i;
            r >= 0 && n.paymentTypes.splice(r, 1);
            i = n.unknownPaymentTypes.indexOf(t);
            i >= 0 && n.unknownPaymentTypes.splice(i, 1)
        },
        k = function(n) {
            return ["储值卡本金", "储值卡馈赠金", "现金券本金", "现金券馈赠金"].indexOf(n.name) >= 0
        },
        d = function() {
            var t = _.filter(n.paymentTypes, function(n) {
                return n.isDefaultUpgrade
            });
            e.batchUpgradePaymentType(t).then(function() {
                h()
            })
        };
    (function() {
        n.cancelUpgrade = a;
        n.moveUpgradedPaymentType = v;
        n.refreshPaymentTypeCache = p;
        n.checkIsUpgradeComplete = y;
        n.completeUpgrade = h;
        n.deletePaymentTypePromise = w;
        n.isPaymentTypeEditDisabled = k;
        n.forceUpgrade = d
    })()
}]);
practiceModule.controller("PracticePaymentTypeCtrl", ["$scope", "$q", "officeOptionSvc", "enums", "dataDicSvc", "permissionProvider", "moduleOptionProvider", function(n, t, i, r, u, f, e) {
    "use strict";
    var o = function() {
        var o = t.defer(),
            s = u.officeBaseDataOptionDic.load().then(function(t) {
                var i = _.find(t, function(n) {
                    return n.category == r.BaseDataCategory.ChargeItem
                });
                n.isUseParentChargeItem = i && i.isParentEnabled
            }),
            h = [i.optionKeys.PaymentTypeUpgradeStatus, i.optionKeys.IsNewPaymentTypeEnabled],
            c = i.getOfficeOptions(h).then(function(t) {
                if (t && t.length >= 1) {
                    var i = t[0];
                    n.isUpgradeStart = i == r.PaymentTypeUpgradeStatus.Started;
                    n.isUpgradeComplete = i == r.PaymentTypeUpgradeStatus.Finished || i == r.PaymentTypeUpgradeStatus.InitUpgraded;
                    n.isUpgradeUnstart = !n.isUpgradeStart && !n.isUpgradeComplete;
                    n.isInitUpgraded = i == r.PaymentTypeUpgradeStatus.InitUpgraded;
                    n.isShowOld = n.isUpgradeUnstart && !n.isUpgradeStart && !n.isUpgradeComplete;
                    n.isShowNew = !n.isUpgradeUnstart && !n.isUpgradeStart && n.isUpgradeComplete;
                    n.isShowUpgrade = !n.isUpgradeUnstart && n.isUpgradeStart && !n.isUpgradeComplete
                }
                t && t.length == 2 && (n.isNewPaymentTypeEnabled = t[1] == 1)
            });
        return n.hasEditPermission = f.isChargeItemEditAllowed, n.isUpgradeEnabled = e.isPaymentTypeUpgradeEnabled(), n.isCustomCategoryEnabled = e.isCustomPaymentTypeCategoryEnabled(), n.isForceNewReportEnabled = e.isForceNewReportEnabled(), t.all([s, c]).then(function() {
            o.resolve()
        }), o.promise
    };
    (function() {
        o()
    })()
}]);
practiceModule.controller("PracticeSystemconfigChargeCtrl", ["$log", "$scope", "aresDialog", "practiceSvc", function(n, t, i, r) {
    "use strict";
    t.chargeConfig = {};
    var u = function() {
            r.getSystemConfigByType("Charge").success(function(n) {
                if (t.systemConfig = n, n.length > 0)
                    for (var i = 0; i < n.length; i++) n[i].configName == "ApplyCDTCharge" ? (t.chargeConfig.applyCDTChargeId = n[i].id, t.chargeConfig.applyCDTCharge = n[i].configValue == "true" ? !0 : !1) : n[i].configName == "ApplyRCCharge" ? (t.chargeConfig.applyRCChargeId = n[i].id, t.chargeConfig.applyRCCharge = n[i].configValue == "true" ? !0 : !1) : n[i].configName == "AllowSingleDiscount" && (t.chargeConfig.allowSingleDiscountId = n[i].id, t.chargeConfig.allowSingleDiscount = n[i].configValue == "true" ? !0 : !1)
            })
        },
        f = function() {
            for (var n = 0; n < t.systemConfig.length; ++n) t.systemConfig[n].configName == "ApplyCDTCharge" ? t.systemConfig[n].configValue = t.chargeConfig.applyCDTCharge.toString() : t.systemConfig[n].configName == "ApplyRCCharge" ? t.systemConfig[n].configValue = t.chargeConfig.applyRCCharge.toString() : t.systemConfig[n].configName == "AllowSingleDiscount" && (t.systemConfig[n].configValue = t.chargeConfig.allowSingleDiscount.toString());
            r.updateSystemConfigList(t.systemConfig).success(function() {
                i.info("信息", "更新成功")
            })
        };
    (function() {
        t.systemConfig = [];
        t.init = u;
        t.saveConfig = f;
        t.init()
    })()
}]);
practiceModule.controller("PracticeSystemconfigDashboardCtrl", ["$log", "$scope", "membershipSvc", "aresDialog", "practiceSvc", function(n, t, i, r, u) {
    "use strict";
    t.protection = {};
    t.dashboard = {};
    var o = !1,
        f = function() {
            u.getSystemConfigByType("Dashboard").success(function(n) {
                if (n.length > 0) {
                    for (var i = 0; i < n.length; i++) n[i].configName == "protectionAmount" && (t.protection.id = n[i].id, t.protection.isProtectionAmount = n[i].configValue == "True" ? !0 : !1);
                    o = !0
                }
            });
            u.getSystemConfigByType("Dashboards").success(function(n) {
                if (n.length > 0)
                    for (var i = 0; i < n.length; i++) n[i].configValue = n[i].configValue == "True" ? !0 : !1, (n[i].displayOrder == null || n[i].displayOrder != i) && (n[i].displayOrder = i);
                t.dashboard = n
            })
        },
        s = function() {
            var n = {};
            n.id = t.protection.id;
            n.configName = "protectionAmount";
            n.configValue = t.protection.isProtectionAmount;
            n.coments = "";
            n.configType = "Dashboard";
            t.systemConfig.push(n)
        },
        h = function() {
            t.systemConfig = [];
            s();
            t.systemConfigs = {
                systemConfigList: t.systemConfig
            };
            o ? u.updateSystemConfigList(t.systemConfig).success(function() {
                f();
                t.showNotification("保存成功！")
            }) : u.createSystemConfigList(t.systemConfig).success(function() {
                f();
                t.showNotification("保存成功！")
            })
        },
        c = function(n) {
            var f;
            if (n != 0) {
                var i = t.dashboard[n - 1],
                    r = t.dashboard[n],
                    o = t.dashboard[i.displayOrder],
                    s = i.displayOrder;
                t.dashboard.splice(i.displayOrder, 1, t.dashboard[r.displayOrder]);
                t.dashboard.splice(r.displayOrder, 1, o);
                f = r.displayOrder;
                t.dashboard[i.displayOrder].displayOrder = o.displayOrder;
                t.dashboard[f].displayOrder = f;
                u.updateSystemConfigList(t.dashboard).success(function() {
                    e()
                })
            }
        },
        l = function(n) {
            var f;
            if (n != t.dashboard.length) {
                var i = t.dashboard[n + 1],
                    r = t.dashboard[n],
                    o = t.dashboard[i.displayOrder],
                    s = i.displayOrder;
                t.dashboard.splice(i.displayOrder, 1, t.dashboard[r.displayOrder]);
                t.dashboard.splice(r.displayOrder, 1, o);
                f = r.displayOrder;
                t.dashboard[i.displayOrder].displayOrder = o.displayOrder;
                t.dashboard[f].displayOrder = f;
                u.updateSystemConfigList(t.dashboard).success(function() {
                    e()
                })
            }
        },
        e = function() {
            $("#dashboardList").load()
        },
        a = function(n) {
            u.updateSystemConfig(t.dashboard[n]).success(function() {
                e()
            })
        };
    (function() {
        f();
        t.saveProtection = h;
        t.up = c;
        t.down = l;
        t.updateConfig = a
    })()
}]);
practiceModule.controller("PracticeSystemconfigEmrCtrl", ["$log", "$scope", "membershipSvc", "aresDialog", "practiceSvc", function(n, t, i, r, u) {
    "use strict";
    t.EMRTimeLimit = {};
    t.EMRTimeLimit.isDisableTimeLimit = !1;
    var e = !1,
        f = function() {
            u.getSystemConfigByType("EMR").success(function(n) {
                if (n.length > 0) {
                    for (var i = 0; i < n.length; i++) n[i].configName == "EMRTimeLimit" ? (t.EMRTimeLimit.timeLimitId = n[i].id, t.EMRTimeLimit.timeLimit = n[i].configValue) : n[i].configName == "IsDisableEMRTimeLimit" && (t.EMRTimeLimit.isDisableTimeLimitId = n[i].id, t.EMRTimeLimit.isDisableTimeLimit = n[i].configValue.toUpperCase() == "TRUE" ? !0 : !1);
                    e = !0
                }
            })
        },
        o = function() {
            var n = {};
            n.id = t.EMRTimeLimit.timeLimitId;
            n.configName = "EMRTimeLimit";
            n.configValue = t.EMRTimeLimit.timeLimit;
            n.coments = "";
            n.configType = "EMR";
            t.systemConfig.push(n)
        },
        s = function() {
            var n = {};
            n.id = t.EMRTimeLimit.isDisableTimeLimitId;
            n.configName = "IsDisableEMRTimeLimit";
            n.configValue = t.EMRTimeLimit.isDisableTimeLimit;
            n.coments = "";
            n.configType = "EMR";
            t.systemConfig.push(n)
        },
        h = function() {
            if (t.EMRTimeLimit.isDisableTimeLimit) {
                if (t.EMRTimeLimit.timeLimit.toString() == "") {
                    r.warn("提示", "时效不能为空！");
                    return
                }
                if (isNaN(t.EMRTimeLimit.timeLimit * 1)) {
                    r.warn("提示", "时效必须为数字!");
                    return
                }
            }
            t.systemConfig = [];
            t.EMRTimeLimit.isDisableTimeLimit && o();
            s();
            t.systemConfigs = {
                systemConfigList: t.systemConfig
            };
            e ? u.updateSystemConfigList(t.systemConfig).success(function() {
                f();
                t.showNotification("保存成功！")
            }) : u.createSystemConfigList(t.systemConfig).success(function() {
                f();
                t.showNotification("保存成功！")
            })
        };
    (function() {
        f();
        t.saveEMR = h
    })()
}]);
practiceModule.directive("paymentTypeCreateDialogView", ["$log", "$timeout", "dataDicSvc", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/dialogs/payment-type/payment-type-create-dialog-view.html",
        link: function(n, i) {
            var u = function() {
                    i.find("#paymentTypeCategory").kendoDropDownList({
                        optionLabel: "--请选择类型--",
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: n.paymentTypeCategories,
                        change: function(t) {
                            var i = this.dataItem(t.item);
                            n.onPaymentTypeCategoryChanged(i);
                            n.$apply()
                        }
                    });
                    n.currentPaymentType.categoryId && r(n.currentPaymentType.categoryId)
                },
                r = function(n) {
                    var t = i.find("#paymentTypeCategory").data("kendoDropDownList");
                    t && t.value(n)
                },
                f = function() {
                    i.find("#paymentTypeName").bind("blur", function() {
                        var t = n.getPinyin();
                        n.currentPaymentType.pinyin = t;
                        i.find("#paymentTypePy").val(t)
                    })
                },
                e = function() {
                    var n = i.find("#paymentTypeCategory").data("kendoDropDownList");
                    n && n.enable(!1)
                };
            (function() {
                n.disableCategoryDropdownlist = e;
                n.setCategoryDropdownlistValue = r;
                u();
                f();
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.controller("PaymentTypeCreateDialogCtrl", ["$scope", "$modalInstance", "$timeout", "$q", "aresNotification", "host", "enums", "paymentTypeSvc", "pinyinUtil", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    var v = function() {
            var t = f.paymentType,
                i;
            n.currentSrcPaymentType = t;
            n.currentPaymentType = angular.copy(t);
            n.currentPaymentType.originName = t.name;
            (!n.currentPaymentType.incomeType || n.currentPaymentType.incomeType <= 0) && (n.currentPaymentType.incomeType = e.IncomeType.Cash);
            n.unknownPaymentTypes.forEach(function(n) {
                n.isSelected = !1
            });
            i = _.find(n.unknownPaymentTypes, function(t) {
                return t.name == n.currentPaymentType.name
            });
            i && (i.isSelected = !0)
        },
        h = function(t) {
            n.unknownPaymentTypes.forEach(function(n) {
                n.isSelected = !1
            });
            t.isSelected = !0;
            n.currentSrcPaymentType = t;
            n.currentPaymentType = angular.copy(t);
            n.currentPaymentType.originName = t.name;
            (!n.currentPaymentType.categoryId || n.currentPaymentType.categoryId <= 0) && (n.currentPaymentType.categoryId = 0);
            n.setCategoryDropdownlistValue(n.currentPaymentType.categoryId)
        },
        c = function() {
            for (var u, t, r = !1, f = n.unknownPaymentTypes.indexOf(n.currentSrcPaymentType), e = n.unknownPaymentTypes.length, i = f; i < e - 1; i++)
                if (!n.unknownPaymentTypes[i + 1].isUpgrade) {
                    t = n.unknownPaymentTypes[i + 1];
                    r = !0;
                    break
                }(r || (u = n.unknownPaymentTypes.filter(function(n) {
                    return !n.isUpgrade
                }), t = u[0]), t) && h(t)
        },
        y = function(t) {
            var i = r.defer();
            return t.isEnabled = !1, o.upgradePaymentType(t).then(function() {
                n.currentSrcPaymentType.name = t.name;
                n.currentSrcPaymentType.code = t.code;
                n.currentSrcPaymentType.incomeType = t.incomeType;
                n.currentSrcPaymentType.categoryId = t.categoryId;
                n.currentSrcPaymentType.isUpgrade = !0;
                i.resolve()
            }, function() {
                u.error("保存失败");
                i.reject()
            }), i.promise
        },
        p = function() {
            n.currentPaymentType = {
                id: 0,
                incomeType: e.IncomeType.Cash,
                code: "",
                name: "",
                itemType: "收费方式",
                notes: "",
                isEnabled: !0,
                isDefault: !1,
                categoryId: null
            }
        },
        w = function(n) {
            b(n) && l(n) && o.createNewPaymentType(n).then(function(n) {
                u.success("保存成功");
                t.close(n.data)
            }, function() {
                u.error("保存失败")
            })
        },
        b = function(t) {
            var r = n.allPaymentTypes.find(function(n) {
                    return n.id && n.name == t.name
                }),
                i;
            if (r) return u.error("已存在支付方式：" + t.name + "！"), !1;
            if (i = n.allPaymentTypes.find(function(n) {
                    return n.id && n.code == t.code
                }), i && t.code) {
                u.error("已存在编码为" + t.code + "的支付方式！");
                return
            }
            return !0
        },
        l = function(t) {
            return n.defaultPaymentTypeNames.indexOf(t.name) >= 0 ? (u.error("系统默认支付方式不允许手动添加！"), !1) : !0
        },
        k = function(n) {
            (n.name == n.originName || l(n)) && o.updatePaymentType(n).then(function(n) {
                u.success("保存成功");
                t.close(n.data)
            }, function() {
                u.error("保存失败")
            })
        },
        d = function() {
            if (tt()) {
                nt();
                var i = angular.copy(n.currentPaymentType);
                i.originName = n.currentPaymentType.originName;
                n.action == "upgrade" ? y(i).then(function() {
                    g();
                    n.leftUnupgradeCount > 0 ? c() : t.close()
                }) : n.action == "create" ? w(i) : k(i)
            }
        },
        g = function() {
            var t = n.unknownPaymentTypes.filter(function(n) {
                return !n.isUpgrade
            });
            n.leftUnupgradeCount = t ? t.length : 0
        },
        nt = function() {
            var i = n.currentPaymentType.newPaymentTypeConfigs,
                t;
            i && i.length != 0 && (i.forEach(function(t) {
                t.name && t.name != "" || (t.name = n.currentPaymentType.name)
            }), t = n.currentPaymentType.paymentTypeConfigs, t && t.length != 0) && t.forEach(function(t) {
                t.name && t.name != "" || (t.name = n.currentPaymentType.name)
            })
        },
        tt = function() {
            var t = n.currentPaymentType,
                i, r, f;
            return t.categoryId ? t.name ? (i = [], n.paymentTypeCategories.forEach(function(n) {
                n.paymentTypes && n.paymentTypes.length > 0 && (i = i.concat(n.paymentTypes))
            }), r = !1, f = !1, t.id == 0 ? (r = _.any(i, function(n) {
                return n.name == t.name
            }), f = _.any(i, function(n) {
                return t.code != "" && n.code == t.code
            })) : (r = _.any(i, function(n) {
                return n.name == t.name && n.id != t.id
            }), f = _.any(i, function(n) {
                return t.code && t.code != "" && n.code == t.code && n.id != t.id
            })), r) ? (u.error("已经存在同名的支付方式"), !1) : f ? (u.error("已经存在相同编码的支付方式"), !1) : !0 : (u.error("支付方式名称不能为空"), !1) : (u.error("请选择支付方式类型"), !1)
        },
        it = function() {
            var t = f.paymentType;
            n.action = f.action;
            n.action == "upgrade" ? v() : n.action == "create" ? p() : rt(t);
            ut();
            ft()
        },
        rt = function(t) {
            n.currentSrcPaymentType = t;
            n.currentPaymentType = angular.copy(t);
            n.currentPaymentType.originName = t.name
        },
        ut = function() {
            if (n.action != "create")["储值卡本金", "储值卡馈赠金", "现金券本金", "现金券馈赠金", "不记名卡本金", "不记名卡馈赠金", "汇付/扫一扫/微信", "汇付/扫一扫/支付宝", "汇付/扫一扫/云闪付", "汇付/小白盒/微信", "汇付/小白盒/支付宝", "汇付/小白盒/云闪付", "银联/小白盒/微信", "银联/小白盒/支付宝", "银联/小白盒/云闪付", "一体支付/银行卡", "汇付/银行卡", "支付宝标品采购价", "支付宝标品优惠", "微医保采购价", "微医保优惠", "天猫拼多多采购价", "天猫拼多多优惠", "京东健康采购价", "京东健康优惠", ].indexOf(n.currentPaymentType.name) >= 0 && i(function() {
                n.disableCategoryDropdownlist()
            }, 500)
        },
        ft = function() {
            if (n.currentPaymentType.categoryId > 0) {
                var t = _.find(n.paymentTypeCategories, function(t) {
                    return t.id == n.currentPaymentType.categoryId
                });
                t && a(t)
            }
        },
        et = function() {
            var i = "",
                t;
            return n.currentPaymentType.name && n.currentPaymentType.name.trim() != "" ? (t = s.getPy(n.currentPaymentType.name), t && t.length > 0 && (i = t[0])) : i = "", i
        },
        a = function(t) {
            if (n.currentPaymentTypeCategory = t, n.currentCategoryName = t.name, n.currentPaymentType.categoryId = t.id, n.currentCategoryPaymentTypes = t.paymentTypes, n.currentCategoryConfigs = angular.copy(n.currentPaymentTypeCategory.configs), n.currentSrcPaymentType && (n.currentSrcPaymentType.name == "支付宝标品采购价" || n.currentSrcPaymentType.name == "微医保采购价" || n.currentSrcPaymentType.name == "天猫拼多多采购价" || n.currentSrcPaymentType.name == "京东健康采购价")) {
                var i = _.find(n.currentCategoryConfigs, n => n.scenario == 1);
                i && (i.isInCashFlow = !0)
            }
        },
        ot = ["汇付/扫一扫/微信", "汇付/扫一扫/支付宝", "汇付/扫一扫/云闪付", "汇付/小白盒/微信", "汇付/小白盒/支付宝", "汇付/小白盒/云闪付", "银联/小白盒/微信", "银联/小白盒/支付宝", "银联/小白盒/云闪付", "银联/二维码", "健康山西", "一体支付/银行卡", "汇付/银行卡", "银联/Pos", "支付宝标品采购价", "支付宝标品优惠", "微医保采购价", "微医保优惠", "天猫拼多多采购价", "天猫拼多多优惠", "京东健康采购价", "京东健康优惠", ],
        st = function(n) {
            return n.isDefault || ot.indexOf(n.name) >= 0
        };
    (function() {
        n.defaultPaymentTypeNames = [];
        n.paymentTypeCategories = f.paymentTypeCategories;
        n.allPaymentTypes = f.allPaymentTypes;
        n.unknownPaymentTypes = f.unknownPaymentTypes;
        n.defaultPaymentTypeNames = f.defaultPaymentTypeNames;
        n.setCurrentPaymentType = h;
        n.isEditNameDisabled = st;
        n.save = d;
        n.next = c;
        n.getPinyin = et;
        n.leftUnupgradeCount = f.unknownPaymentTypes ? f.unknownPaymentTypes.length : 0;
        n.onPaymentTypeCategoryChanged = a;
        it()
    })()
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.templateUrl = "/app/practice/dialogs/payment-type-category/payment-type-category-create-dialog-view.html";
            this.link = function() {}
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("paymentTypeCategoryCreateDialogView", Ares.tsDirective(n))
})(practice || (practice = {}));
var practice;
(function() {
    "use strict";
    var t = function() {
            function n(n, t, i, r, u) {
                this.id = n;
                this.name = t;
                this.isDefault = i;
                this.notes = r;
                this.configs = u
            }
            return n
        }(),
        n = function() {
            function n(n, t, i, r, u, f) {
                this.categoryId = n;
                this.scenario = t;
                this.scenarioName = i;
                this.isEnabled = r;
                this.isInCashFlow = u;
                this.isIncome = f;
                this.isInPerformance = f;
                this.isInAdvacne = !1;
                this.isOutAdvance = !1
            }
            return n
        }(),
        i = function() {
            function i(n, t, i, r, u, f, e, o) {
                var s = this;
                this.$scope = n;
                this.$q = t;
                this.paymentTypeSvc = i;
                this.$modalInstance = r;
                this.aresNotification = u;
                this.host = f;
                this.officeOptionSvc = e;
                this.dataDicSvc = o;
                this._diagnosisChargeScenarios = [1, 6, 7];
                this._diagnosisScenarioTypeName = "common";
                this._giftScenarioTypeName = "gift";
                n.currentCategoryScenario = {
                    isCommonChargeEnabled: !0,
                    isAdvanceChargeEnabled: !0
                };
                n.action = this.host.action;
                n.isOnlyShow = this.host.action == "info";
                this.initConfig().then(function() {
                    s.initData();
                    s.initScenarioEnabled()
                })
            }
            return i.prototype.initConfig = function() {
                var n = this;
                return this.dataDicSvc.officeSettingDic.load().then(function(t) {
                    n.isCheckInAdvanceChargeEnabled = t.isCheckInAdvanceChargeEnabled
                })
            }, i.prototype.initData = function() {
                var r = angular.copy(this.host.category),
                    i;
                r == null && (i = [new n(0, 1, "收费", !0, !0, !0), new n(0, 2, "预付款（储值卡）交易", !0, !1, !0), new n(0, 3, "现金卡券售卖", !0, !1, !0), new n(0, 4, "折扣卡券售卖", !0, !0, !0), new n(0, 5, "套餐卡券售卖", !0, !0, !0), new n(0, 6, "划扣收费", !0, !0, !1), new n(0, 7, "划扣确认", !0, !1, !0), new n(0, 8, "划扣收费进预收", !0, !1, !0), new n(0, 9, "折扣卡券售卖进预收", !0, !1, !0), new n(0, 10, "套餐卡券售卖进预收", !0, !1, !0), new n(0, 11, "不记名卡交易", !0, !1, !0), ], this.isCheckInAdvanceChargeEnabled && (i = i.concat([new n(0, 12, "挂号费预收", !0, !0, !1), new n(0, 13, "挂号费预收确认", !0, !1, !0)])), r = new t(0, "", !1, "", i));
                this.$scope.currentPaymentTypeCategory = r;
                this._srcIsPlatformChargeIncome = this.$scope.currentPaymentTypeCategory.isPlatformChargeIncomeEnabled;
                this.sortPaymentTypeCategoryConfigs()
            }, i.prototype.sortPaymentTypeCategoryConfigs = function() {
                var n = this,
                    t = this.$scope.currentPaymentTypeCategory.configs;
                t.forEach(function(t) {
                    t.scenarioType = n._diagnosisChargeScenarios.indexOf(t.scenario) >= 0 ? n._diagnosisScenarioTypeName : n._giftScenarioTypeName
                });
                this.$scope.currentPaymentTypeCategory.configs = t.sort(function(n, t) {
                    return n.scenarioType < t.scenarioType ? -1 : 1
                })
            }, i.prototype.initScenarioEnabled = function() {
                var n = this.$scope.currentPaymentTypeCategory.configs,
                    t = _.find(n, function(n) {
                        return n.scenario == 1
                    }),
                    i = _.find(n, function(n) {
                        return n.scenario == 2
                    });
                this.$scope.currentCategoryScenario.isCommonChargeEnabled = t ? t.isEnabled : !0;
                this.$scope.currentCategoryScenario.isAdvanceChargeEnabled = i ? i.isEnabled : !0
            }, i.prototype.scenarioEnabledChanged = function() {
                var n = this,
                    i = this.$scope.currentPaymentTypeCategory.configs,
                    t = this.$scope.currentCategoryScenario;
                i.forEach(function(i) {
                    i.isEnabled = n._diagnosisChargeScenarios.indexOf(i.scenario) >= 0 ? t.isCommonChargeEnabled : t.isAdvanceChargeEnabled;
                    n.cancelScenarioConfig(i)
                })
            }, i.prototype.cancelScenarioConfig = function(n) {
                n.isEnabled || (n.isInCashFlow = !1, n.isIncome = !1)
            }, i.prototype.save = function() {
                var n = this,
                    t;
                this.validate() && (t = this.$scope.currentPaymentTypeCategory.id && this.$scope.currentPaymentTypeCategory.id != 0 ? this.updateCategory() : this.createCategory(), t.then(function(t) {
                    n.$scope.currentPaymentTypeCategory.name === "平台结算" && n._srcIsPlatformChargeIncome != n.$scope.currentPaymentTypeCategory.isPlatformChargeIncomeEnabled && (n.officeOptionSvc.refreshOfficeOption(n.officeOptionSvc.optionKeys.IsPlatformChargeIncomeEnabled, n.$scope.currentPaymentTypeCategory.isPlatformChargeIncomeEnabled), n.dataDicSvc.paymentTypeCategoryDic.refresh());
                    n.$modalInstance.close(t.data)
                }))
            }, i.prototype.validate = function() {
                return !this.$scope.currentPaymentTypeCategory.name || this.$scope.currentPaymentTypeCategory.name.trim() == "" ? (this.aresNotification.error("请输入类型名称"), !1) : !0
            }, i.prototype.createCategory = function() {
                var n = this.$q.defer();
                return this.paymentTypeSvc.createPaymentTypeCategory(this.$scope.currentPaymentTypeCategory).then(function(t) {
                    n.resolve(t)
                }), n.promise
            }, i.prototype.updateCategory = function() {
                var n = this.$q.defer();
                return this.paymentTypeSvc.updatePaymentTypeCategory(this.$scope.currentPaymentTypeCategory).then(function(t) {
                    n.resolve(t)
                }), n.promise
            }, i.prototype.cancel = function() {
                this.$modalInstance.close()
            }, i.$inject = ["$scope", "$q", "paymentTypeSvc", "$modalInstance", "aresNotification", "host", "officeOptionSvc", "dataDicSvc", ], i
        }();
    practiceModule.controller("PaymentTypeCategoryCreateDialogCtrl", Ares.tsController(i))
})(practice || (practice = {}));
practiceModule.directive("systemSettingItemEditDialogView", ["$log", "$timeout", "dataDicSvc", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/dialogs/system-setting-item-edit-dialog/system-setting-item-edit-dialog-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#ruleSettingForm"), {
                        itemName: {
                            required: !0,
                            systemItemName: !0,
                            maxlength: 20
                        }
                    }, {
                        itemName: {
                            required: "请输入项目名称",
                            systemItemName: "名称已被使用",
                            maxlength: "项目名称不能超过20个字符"
                        }
                    })
                },
                f = function() {
                    i.find("#ruleSettingForm").valid() && n.saveSystemItem()
                },
                e = function() {
                    jQuery.validator.addMethod("systemItemName", function(t) {
                        var i = !0,
                            r;
                        return t && (r = _.some(n.siblings, function(t) {
                            return t.itemName === n.currentSystemItem.itemName && t.id !== n.currentSystemItem.id
                        }), r && (i = !1)), i
                    }, "名称已被使用！")
                };
            (function() {
                e();
                u();
                n.validAndSave = f;
                n.$watch("currentSystemItem", function() {
                    r && Ares.clearError(i.find("#ruleSettingForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.controller("SystemSettingItemEditDialogCtrl", ["$log", "$scope", "$modalInstance", "aresDialog", "aresNotification", "systemSettingItemSvc", "dataDicSvc", "host", function(n, t, i, r, u, f, e, o) {
    "use strict";
    t.cancel = function() {
        i.dismiss("cancel")
    };
    t.saveSystemItem = function() {
            t.currentSystemItem.itemName = t.currentSystemItem.itemName.replace(/\s/g, "");
            var n = _.some(t.siblings, function(n) {
                return n.itemName === t.currentSystemItem.itemName && n.id !== t.currentSystemItem.id
            });
            if (n) {
                r.warn("警告", "已经有其他项目使用此名称，请更换新名称！");
                return
            }
            f.updateSystemSettingItem(t.currentSystemItem).success(function(n) {
                u.success("保存成功！");
                i.close(n)
            }).error(function(n) {
                n.name === "SystemItemNameNotUniqueException" && r.warn("警告", "已经有其他项目使用此名称，请更换新名称！")
            })
        },
        function() {
            t.currentSystemItem = o.currentSystemItem;
            t.siblings = o.siblings;
            t.dataTypeName = o.dataTypeName
        }()
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.template = '\n            <div class="schedule-rule-view-new" style="width: 100%; height: 100%;">\n                <ares-new-home-view target-route="officeSettings.medicalRecordSetting" style="height: 100%"><\/ares-new-home-view>\n            <\/div>\n        '
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("ares3PracticeEmrConfigView", Ares.tsDirective(n))
})(practice || (practice = {}));
practiceModule.directive("practiceDiagnosisBrowserView", ["$log", "$timeout", "$window", "dataDicSvc", "practiceSvc", "officeUtil", "gridOptionUtil", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-diagnosis-browser-view.html",
        controller: "PracticeDiagnosismBrowserCtrl",
        link: function(n, t) {
            var h = Ares.kendoGridUtil(i, n),
                r = null,
                k;
            n.initList = function() {
                f.isParentEnabled("ChargeItem").then(function(i) {
                    var u, f, o;
                    n.isChargeItemParentEnabled = i;
                    u = [{
                        field: "itemCode",
                        title: "项目编码",
                        width: "140px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "itemName",
                        title: "名称",
                        width: "300px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "itemEnName",
                        title: "英文名",
                        width: "60x",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "pinyin",
                        title: "拼音",
                        width: "100px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }];
                    n.isChargeItemParentEnabled || u.push({
                        template: h.commandTemplate,
                        title: "",
                        width: "150px"
                    });
                    f = $(t).find("#currentChargeItemCatagory");
                    o = $(window).height() - 255 - (window.Ares3 ? 15 : 0);
                    r = f.kendoGrid({
                        dataSource: e.dataSource(c),
                        scrollable: !0,
                        height: o,
                        sortable: !0,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        excel: {
                            allPages: !0
                        },
                        pageable: e.pageable,
                        columns: u
                    }).data("kendoGrid");
                    n.relationGrid = r
                })
            };
            var c = function(t) {
                    n.pageIndex = t.data.page;
                    n.pageSize = t.data.pageSize;
                    n.search().then(function(i) {
                        if (i) {
                            n.totalCount = i.totalCount;
                            var r = {
                                data: i.items,
                                total: i.totalCount
                            };
                            t.success(r)
                        }
                    })
                },
                o = function() {
                    r ? r.dataSource.read() : n.initList()
                },
                s = function() {
                    var t = r.select();
                    n.selectedRowIndex = $("tr", r.tbody).index(t)
                },
                l = function() {
                    s();
                    var i = n.diagnoseItemList[n.selectedRowIndex],
                        t = n.diagnoseItemList[n.selectedRowIndex - 1];
                    t && n.upItem(i, t)
                },
                a = function() {
                    s();
                    var i = n.diagnoseItemList[n.selectedRowIndex],
                        t = n.diagnoseItemList[n.selectedRowIndex + 1];
                    t && n.downItem(i, t)
                },
                v = function(t) {
                    var i = {
                        data: n.diagnoseItemList,
                        total: n.totalCount
                    };
                    r.dataSource.success(i);
                    r.select("#currentChargeItemCatagory tr:eq(" + (t + 1) + ")")
                },
                y = function(t) {
                    var i = {
                        data: n.diagnoseItemList,
                        total: n.totalCount
                    };
                    r.dataSource.success(i);
                    r.select("#currentChargeItemCatagory tr:eq(" + (t + 2) + ")")
                },
                p = [{
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "删除",
                    action: "delete",
                    icon: "glyphicon-remove"
                }, ],
                w = function(t) {
                    return _.find(n.diagnoseItemList, function(n) {
                        return n.id == t
                    })
                },
                b = function(t, i, r) {
                    var u = w(r);
                    switch (i) {
                        case "update":
                            n.editDiagnoseItem(u);
                            break;
                        case "delete":
                            n.deleteDiagnoseItem(u)
                    }
                };
            n.exportItemExcel = function() {
                r && r.saveAsExcel()
            };
            k = function() {
                    u.getDiagnoseItemList().success(function(t) {
                        var r, u, i, f;
                        if (n.searchString == "") {
                            n.isdisable = !1;
                            n.diagnoseItemList = t;
                            o();
                            return
                        }
                        for (n.isdisable = !0, r = [], u = t, i = 0; i < u.length; i++) f = u[i], f.itemName.toLowerCase().indexOf(n.searchString.toLowerCase()) > -1 && r.push(f);
                        n.diagnoseItemList = {};
                        n.diagnoseItemList = r;
                        o()
                    })
                },
                function() {
                    n.$watch("searchString", function() {
                        o()
                    });
                    n.up = l;
                    n.down = a;
                    n.commands = p;
                    n.onCommandClick = b;
                    n.refreshUpDownGrid = v;
                    n.refreshDownGrid = y;
                    n.refreshGrid = o
                }()
        }
    }
}]);
practiceModule.directive("practiceDiagnosisEditView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-diagnosis-edit-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#diagnosisItemForm"), {
                        itemName: {
                            required: !0,
                            maxlength: 200,
                            valItemName: !0
                        },
                        itemCode: {
                            required: !0,
                            maxlength: 200,
                            valItemCode: !0
                        },
                        itemEnName: {
                            required: !0,
                            valItemEnName: !0
                        }
                    }, {
                        itemName: {
                            required: "请输入项目名称",
                            maxlength: "项目名称不能大于200个字！",
                            valItemName: "名称已被使用！"
                        },
                        itemCode: {
                            required: "请输入项目编号",
                            maxlength: "项目编码不能超过200个字符",
                            valItemCode: "编码已被使用！"
                        },
                        itemEnName: {
                            required: "请输入英文名",
                            itemEnName: "英文名已被使用！"
                        }
                    })
                },
                f = function() {
                    i.find("#diagnosisItemForm").valid() && n.saveChargeItem()
                };
            (function() {
                u();
                n.validAndSave = f;
                n.$watch("diagnoseItem", function() {
                    r && Ares.clearError(i.find("#diagnosisItemForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrConfigView", ["$log", "$timeout", "$window", "patientSvc", "aresDialog", "appNav", function(n, t, i, r, u, f) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-emr-config-view.html",
        controller: "PracticeEmrConfigCtrl",
        link: function(n, t) {
            var i = function() {
                    var n = t.find("#emrConfigForm");
                    Ares.validateForm(n, {
                        category: {
                            required: !0
                        }
                    }, {
                        category: {
                            required: "请选择病历启用类型"
                        }
                    })
                },
                r = function() {
                    t.find("#emrConfigForm").valid() && n.saveEmrSettings()
                },
                u = function() {
                    n.isEdit = !n.isEdit
                },
                e = function() {
                    f.reload()
                };
            (function() {
                i();
                n.validAndSave = r;
                n.editConfig = u;
                n.cancel = e
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateBrowserCreateItemView", ["$log", function() {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-emrtemplate-browser-create-item-view.html",
        link: function(n, t) {
            $.validator.addMethod("noSameNameNode", function(t, i, r) {
                return this.optional(i) || !_.some(r.childrenItems, function(i) {
                    return n.newDiseaseItem ? t === i.itemName && n.newDiseaseItem.id !== i.id : t === i.itemName
                })
            }, "已存在同名的同级目录或模板");
            $.validator.addMethod("notEqualToMyTemplate", function(n, t) {
                return this.optional(t) || n !== "我的模板"
            }, "名称不能为“我的模板”");
            var i, r, u = function() {
                    i = Ares.validateForm(t.find("#addDiseaseItemForm"), {
                        itemName: {
                            required: !0,
                            noSameNameNode: n.parentNode,
                            notEqualToMyTemplate: !0
                        }
                    }, {
                        itemName: {
                            required: "请输入目录名称"
                        }
                    });
                    r = Ares.validateForm(t.find("#emrTemplateAddForm"), {
                        templateName: {
                            required: !0,
                            noSameNameNode: n.parentNode,
                            notEqualToMyTemplate: !0
                        }
                    }, {
                        templateName: {
                            required: "请输入模板名称"
                        }
                    })
                },
                f = function() {
                    switch (n.showType) {
                        case 1:
                            t.find("#addDiseaseItemForm").valid() && n.saveDiseaseItem();
                            break;
                        case 2:
                            t.find("#addDiseaseItemForm").valid() && n.saveDiseaseItem();
                            break;
                        case 3:
                            t.find("#emrTemplateAddForm").valid() && n.saveEmrTemplate()
                    }
                };
            (function() {
                u();
                n.save = f;
                n.$watch("newDiseaseItem", function() {
                    i && Ares.clearError(t.find("#addDiseaseItemForm"));
                    r && Ares.clearError(t.find("#emrTemplateAddForm"))
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateBrowserDirectoryMoveView", ["$log", "$timeout", "aresDialog", "loginContext", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/practice-emrtemplate-browser-directory-move-view.html",
        link: function(n) {
            var t = "",
                u = null,
                f, e = function(i) {
                    f = i;
                    t = i.id;
                    n.clickedName = i.itemName;
                    i && (i.departmentName === "我的模板" || i.itemName === "我的模板") && (u = r.userId)
                },
                o = function() {
                    var r = {
                        id: n.currentEmrTemplate.id,
                        diseaseId: t,
                        templateType: n.templateType,
                        layoutTemplateCode: n.templateCode,
                        userId: u
                    };
                    if (!(t === 0 || t)) {
                        i.info("提示", "请选择目录！");
                        return
                    }
                    n.moveTemplate(r)
                };
            (function() {
                n.getContent = e;
                n.sureMoveTemplate = o
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateBrowserView", ["$log", "$q", "$timeout", "$window", "$modal", "patientSvc", "aresDialog", "enums", "loginContext", "constants", "emrUtil", "aresNotification", function(n, t, i, r, u, f, e, o, s, h, c, l) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-emrtemplate-browser-view.html",
        controller: "PracticeEmrtemplateCtrl",
        link: function(i, r) {
            var o = function(n, t, r) {
                    var e = {
                            type: t,
                            itemData: n
                        },
                        f;
                    r && (e.isEmrCustomTemplateEnabled = i.isEmrCustomTemplateEnabled);
                    switch (t) {
                        case 1:
                            f = i.templateTreeControl.getParent(n);
                            break;
                        case 2:
                            f = n;
                            break;
                        case 3:
                            f = n
                    }
                    return e.parentNode = f, u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-emrtemplate-browser-create-item-view><\/practice-emrtemplate-browser-create-item-view>",
                        controller: "PracticeEmrtemplateBrowserCreateItemCtrl",
                        windowClass: r ? "emrtemplate-browser-create-item" : "emrtemplate-browser-create-directory",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return e
                            }
                        }
                    })
                },
                a = function(t, r) {
                    var u = o(t, r);
                    u.result.then(function(r) {
                        t.id === 0 && t.itemName === "我的模板" && (r.ownerId = s.userId);
                        t.ownerId && (r.ownerId = s.userId);
                        f.createDiseaseItem(r).success(function(n) {
                            i.templateTreeControl.addBranch(n)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                v = function() {
                    a({
                        id: 0
                    }, 2)
                },
                y = function(t, r) {
                    var u = o(t, r);
                    u.result.then(function(t) {
                        f.updateDiseaseItem(t).success(function() {
                            i.templateTreeControl.updateBranch(t)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                p = function(t) {
                    if (i.deleteDiseaseItem = angular.copy(t), t.childrenItems && t.childrenItems.length > 0) {
                        e.info("提示", "该模板目录下还有可用的模板，不能删除！");
                        return
                    }
                    e.confirm("提示", "确认删除目录" + i.deleteDiseaseItem.itemName).then(function() {
                        f.deleteDiseaseItem(i.deleteDiseaseItem.id).success(function() {
                            i.templateTreeControl.deleteBranch(i.deleteDiseaseItem)
                        }).error(function(t) {
                            n.error(t)
                        })
                    })
                },
                w = function(t, r) {
                    var u = o(t, r, 1);
                    u.result.then(function(r) {
                        t.ownerId && (r.userId = s.userId);
                        r.layoutTemplateCode = i.layoutTemplateCode;
                        r.templateType = c.getTemplateTypeByCode(i.layoutTemplateCode);
                        f.createEMRTemplate(r).success(function(n) {
                            i.templateTreeControl.addLeaf(n)
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                b = function(t) {
                    if (i.deleteEMRTemplate = angular.copy(t), t.childrenItems && t.childrenItems.length > 0) {
                        e.info("提示", "该模板目录下还有可用的模板，不能删除！");
                        return
                    }
                    e.confirm("提示", "确认删除病历模板" + i.deleteEMRTemplate.templateName).then(function() {
                        f.deleteEMRTemplate(i.deleteEMRTemplate.id).success(function() {
                            i.templateTreeControl.deleteLeaf(i.deleteEMRTemplate);
                            i.currentEmrTemplate = {};
                            i.selectedNoe = null
                        }).error(function(t) {
                            n.debug(t)
                        })
                    })
                },
                k = function(n) {
                    n.spriteCssClass === "image" ? b(n) : p(n)
                },
                d = function(n) {
                    if (i.isEditEmrTemplate) {
                        e.warn("提示", "当前编辑的模板未保存，请保存或取消后再进行其他操作");
                        i.selectedNode = angular.copy(i.currentEmrTemplate);
                        return
                    }
                    i.layoutTemplateCode = n;
                    i.browserEMRTemplateSetting(i.layoutTemplateCode)
                },
                g = function(n) {
                    i.diseaseItemName = i.templateTreeControl.getBranchBreadcrumbById(n)
                },
                nt = function(n) {
                    if (n && n.spriteCssClass === "image") {
                        if (i.isEditEmrTemplate) {
                            i.selectedNode = angular.copy(i.currentEmrTemplate);
                            e.warn("提示", "当前编辑的模板未保存，请保存或取消后再进行其他操作");
                            return
                        }
                        i.currentEmrTemplate = angular.copy(n);
                        i.showSaveBtn = !0;
                        i.selectedNode = angular.copy(n);
                        g(n.diseaseId)
                    } else i.currentEmrTemplate = {
                        itemName: n.itemName
                    }, i.showSaveBtn = !1;
                    event.stopPropagation()
                },
                tt = function(n, t) {
                    if (!i.isMyTemplateNodeChild(n) && i.isTemplateParentEnabled) {
                        l.error("使用总部配置，不能编辑");
                        return
                    }
                    switch (t) {
                        case 1:
                            y(n, 1);
                            break;
                        case 2:
                            a(n, 2);
                            break;
                        case 3:
                            w(n, 3);
                            break;
                        case 4:
                            k(n)
                    }
                },
                it = function() {
                    $.validator.addMethod("noSameNameNodeWithScope", function(n, t, r) {
                        var u = r.currentEmrTemplate.templateName === r.savedEmrTemplate.templateName,
                            f = !i.templateTreeControl.checkDuplicateNameSibling(i.currentEmrTemplate);
                        return this.optional(t) || u || f
                    }, "已存在同名的同级目录或模板");
                    $.validator.addMethod("notEqualToMyTemplate", function(n, t) {
                        return this.optional(t) || n !== "我的模板"
                    }, "名称不能为“我的模板”");
                    Ares.validateForm(r.find("#emrTemplateForm"), {
                        templateName: {
                            required: !0,
                            noSameNameNodeWithScope: i
                        }
                    }, {
                        templateName: {
                            required: "请输入模板名称"
                        }
                    })
                },
                rt = function() {
                    r.find("#emrTemplateForm").valid() && i.saveEmrTemplate()
                };
            (function() {
                i.layoutTemplateCode = h.firstVisitTemplateCode;
                i.changeType = d;
                i.showSelected = nt;
                i.templateOperate = tt;
                i.addDiseaseItem = v;
                i.diseaseItemName = [];
                i.saveEmrTemplateWithValidation = rt;
                t.all([i.initOfficeOption(), i.initEHRParentEnabled()]).then(function() {
                    i.browserEMRTemplateSetting(i.layoutTemplateCode)
                });
                it();
                i.$watch("isEditEmrTemplate", function() {
                    var n = r.find("#emrTemplateForm");
                    n.data("validator") && Ares.clearError(n)
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateItemMainTypeView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-emrtemplate-item-main-type-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#ruleSettingForm"), {
                        mainType: {
                            required: !0,
                            maxlength: 30
                        }
                    }, {
                        mainType: {
                            required: "请输入大类名称",
                            maxlength: "大类名称不能超过30个字符"
                        }
                    })
                },
                f = function() {
                    i.find("#ruleSettingForm").valid() && n.saveEmrTemplateItemMainType()
                };
            (function() {
                u();
                n.validAndSave = f;
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateItemsettingCategoryView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-emrtemplate-itemsetting-category-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#ruleSettingForm"), {
                        subType: {
                            required: !0,
                            maxlength: 30
                        }
                    }, {
                        subType: {
                            required: "请输入类目名称",
                            maxlength: "类目名称不能超过30个字符"
                        }
                    })
                },
                f = function() {
                    i.find("#ruleSettingForm").valid() && n.saveEmrtemplageItemSetting()
                };
            (function() {
                u();
                n.validAndSave = f;
                n.$watch("mainType", function() {
                    r && Ares.clearError(i.find("#ruleSettingForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.directive("practiceEmrtemplateItemsettingView", ["$log", "$q", "$timeout", "$window", "$modal", "patientSvc", "aresDialog", "practiceSvc", "dataDicSvc", "aresNotification", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-emrtemplate-itemsetting-view.html",
        controller: "PracticeEmrtemplateItemSettingCtrl",
        link: function(n) {
            var t = function() {
                    return n.isEdit ? (e.warn("提示", "请先保存编辑中的内容"), !0) : !1
                },
                i = function(i, u) {
                    var f = t();
                    f || (n.mainType = i, n.subTypesMap = {
                        mainType: i.itemName,
                        subTypes: []
                    }, n.showSubTypeIndex = u, angular.forEach(n.emrTemplateItemSettingData, function(t) {
                        t.mainType == i.itemName && (n.subTypesMap = t)
                    }), r(n.subTypesMap.subTypes[0], 0), n.isShowSubType = 0)
                },
                r = function(i, r) {
                    var u = t();
                    u || (n.subItems = i, n.showItemIndex = r, n.isEdit = !1)
                },
                f = function(n) {
                    var i, t;
                    if (n.length === 0) return 0;
                    for (i = n[0].subTypeOrder, t = 0; t < n.length; t++) i < n[t].subTypeOrder && (i = n[t].subTypeOrder);
                    return i + 1
                },
                c = function() {
                    var t = f(n.subTypesMap.subTypes),
                        i = u.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<practice-emrtemplate-itemsetting-category-view><\/practice-emrtemplate-itemsetting-category-view>",
                            controller: "PracticeEmrtemplateItemsettingCategoryCtrl",
                            size: "sm",
                            resolve: {
                                host: function() {
                                    return {
                                        id: 0,
                                        mainType: n.mainType.itemName,
                                        subType: "",
                                        order: t
                                    }
                                }
                            }
                        });
                    i.result.then(function(t) {
                        var r = {
                                subType: t.subType,
                                subTypeId: t.id,
                                subTypeOrder: t.order,
                                items: []
                            },
                            i = !1;
                        angular.forEach(n.emrTemplateItemSettingData, function(r) {
                            r.mainType == t.mainType && (n.subTypesMap = r, i = !0)
                        });
                        n.emrTemplateItemSettingData.length === 0 && (n.subTypesMap.subTypes = [], n.subTypesMap.mainType = t.mainType);
                        n.subTypesMap.subTypes.length === 0 && (n.showItemIndex = -1);
                        n.subTypesMap.subTypes.push(r);
                        i || n.emrTemplateItemSettingData.push(n.subTypesMap)
                    })
                },
                l = function() {
                    var t = _.max(n.emrTemplateItemSettingMainTypes, function(n) {
                        return n.displayOrder
                    }).displayOrder;
                    return t + 1
                },
                a = function() {
                    return
                },
                v = function() {
                    if (n.mainType || n.mainType.id) {
                        if (n.mainType.isDefault) {
                            e.warn("信息", "默认词条大类不能重命名");
                            return
                        }
                        var t = u.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<practice-emrtemplate-item-main-type-view><\/practice-emrtemplate-item-main-type-view>",
                            controller: "PracticeEmrtemplateItemMainTypeCtrl",
                            size: "sm",
                            resolve: {
                                host: function() {
                                    return {
                                        mainType: n.mainType,
                                        isEdit: !0
                                    }
                                }
                            }
                        });
                        t.result.then(function(t) {
                            s.emrTemplateItemMainTypeDic.clearCache();
                            _.extend(n.mainType, t);
                            n.subTypesMap.mainType = n.mainType.itemName
                        })
                    }
                },
                y = function() {
                    if (n.mainType || n.mainType.id) {
                        if (n.mainType.isDefault) {
                            e.warn("信息", "默认词条大类不能删除");
                            return
                        }
                        if (n.subTypesMap.mainType == n.mainType.itemName && n.subTypesMap.subTypes && n.subTypesMap.subTypes.length > 0) {
                            e.warn("信息", "词条大类还有子类不能删除");
                            return
                        }
                        o.destroySystemSettingItem(n.mainType.id).success(function() {
                            h.success("删除成功！");
                            n.emrTemplateItemSettingMainTypes = _(n.emrTemplateItemSettingMainTypes).reject(n.mainType);
                            s.emrTemplateItemMainTypeDic.clearCache();
                            n.mainType = n.emrTemplateItemSettingMainTypes[0];
                            i(n.mainType, 0)
                        })
                    }
                },
                p = function(t, i) {
                    var r = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-emrtemplate-itemsetting-category-view><\/practice-emrtemplate-itemsetting-category-view>",
                        controller: "PracticeEmrtemplateItemsettingCategoryCtrl",
                        size: "sm",
                        resolve: {
                            host: function() {
                                return {
                                    id: t.subTypeId,
                                    mainType: i,
                                    subType: t.subType,
                                    order: t.subTypeOrder
                                }
                            }
                        }
                    });
                    r.result.then(function(t) {
                        angular.forEach(n.subTypesMap.subTypes, function(n) {
                            n.subTypeId == t.id && (n.subType = t.subType)
                        })
                    })
                },
                w = function(t, i) {
                    if (t.items.length > 0) {
                        e.warn("提示", "请先清空类目中的内容");
                        return
                    }
                    e.confirm("提示", "确定要删除此类目？").then(function() {
                        n.deleteSubTypeItem(t.subTypeId, i)
                    })
                },
                b = function() {
                    var t = n.subItems.items.length,
                        i = {
                            itemName: "",
                            itemCode: "",
                            itemContent: "",
                            order: t
                        };
                    n.subItems.items.push(i)
                },
                k = function(t, i) {
                    $.trim(t.itemContent) == "" ? n.subItems.items.splice(i, 1) : e.confirm("提示", "确定要删除此内容？").then(function() {
                        n.subItems.items.splice(i, 1)
                    })
                },
                d = function() {
                    if (n.subItems)
                        if (n.itemsCache = angular.copy(n.subItems.items), n.subItems.subTypeId > 0) n.isEdit = !0;
                        else {
                            e.warn("提示", "请选择词条类目");
                            return
                        }
                    else e.warn("提示", "请选择词条类目")
                },
                g = function() {
                    var t = !1;
                    if (angular.forEach(n.subItems.items, function(n) {
                            $.trim(n.itemContent) == "" && (t = !0)
                        }), t) {
                        e.warn("提示", "词条内容不能为空");
                        return
                    }
                    n.saveEmrItemContent(n.subItems.subTypeId)
                },
                nt = function() {
                    n.subItems.items = angular.copy(n.itemsCache);
                    n.isEdit = !1
                },
                tt = function(n, t) {
                    n.itemContent.trim().length > 200 && (n.itemContent = n.itemContent.trim().substr(0, 200));
                    subItems.items[t] = n
                };
            (function() {
                n.changeMainTypeItem = i;
                n.changeSubType = r;
                n.creteSubType = c;
                n.editSubType = p;
                n.deleteSubType = w;
                n.createMainType = a;
                n.editMainType = v;
                n.deleteMainType = y;
                n.createEmrItem = b;
                n.deleteEmrItem = k;
                n.editEmrItem = d;
                n.saveEmrItem = g;
                n.cancelEmrItem = nt;
                n.changeContent = tt
            })()
        }
    }
}]);

practiceModule.directive("practiceOperatoryBrowserView", ["$log", "$timeout", "$window", function(n, t, i) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-operatory-browser-view.html",
        controller: "PracticeOperatoryBrowserCtrl",
        link: function(n, r) {
            var f = Ares.kendoGridUtil(i, n),
                u = null,
                e = function() {
                    var i, e;
                    n.commands = [{
                        text: "编辑",
                        action: "editOperatory",
                        icon: "glyphicon glyphicon-edit"
                    }, {
                        text: "删除",
                        action: "deleteOperatory",
                        icon: "glyphicon glyphicon-trash"
                    }];
                    i = r.find("#operatoryList");
                    e = $(window).height() - 120 - (window.Ares3 ? 50 : 0);
                    u = i.kendoGrid({
                        dataSource: {
                            data: n.operators
                        },
                        height: e,
                        scrollable: window.Ares3,
                        sortable: !1,
                        selectable: "single",
                        model: {
                            id: "id"
                        },
                        columns: [{
                            field: "name",
                            title: "诊室编号"
                        }, {
                            field: "description",
                            title: "诊室说明"
                        }, {
                            field: "providerNameStr",
                            title: "关联医生\t"
                        }, {
                            template: f.commandTemplate,
                            title: "",
                            width: "100px"
                        }],
                        change: function() {
                            var i = this.dataItem(this.select());
                            t(function() {
                                n.selectedItem = i ? i : null
                            })
                        }
                    }).data("kendoGrid")
                },
                o = function(t, i, r) {
                    n.$apply(function() {
                        switch (i) {
                            case "editOperatory":
                                n.editOperatory(r);
                                break;
                            case "deleteOperatory":
                                n.deleteOperator(r)
                        }
                    })
                },
                s = function() {
                    u ? (u.dataSource.data(n.operators), h()) : e()
                },
                h = function() {
                    if (n.selectedItem) {
                        var i = u.dataSource,
                            r = i.get(n.selectedItem.id),
                            t = u.element.find("tbody>tr[data-uid=" + r.uid + "]");
                        t && u.select(t)
                    }
                };
            (function() {
                n.onCommandClick = o;
                n.$watch("operators", function() {
                    n.operators && s()
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceOperatoryEditView", ["$log", "$timeout", "practiceSvc", function(n, t, i) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-operatory-edit-view.html",
        link: function(n, r) {
            var u, f = function() {
                    u = Ares.validateForm(r.find("#practiceForm"), {
                        name: {
                            required: !0,
                            maxlength: 30
                        },
                        description: {
                            required: !0,
                            maxlength: 500
                        }
                    }, {
                        name: {
                            required: "请输入诊室编号",
                            maxlength: "诊室编号不能大于30个字！"
                        },
                        description: {
                            required: "请输入诊室说明",
                            maxlength: "诊室说明不能超过500个字符"
                        }
                    })
                },
                e = function() {
                    i.getDoctors().success(function(t) {
                        r.find("#doctors").kendoMultiSelect({
                            dataTextField: "name",
                            dataValueField: "id",
                            dataSource: t,
                            value: n.currentOperator.providers ? _.map(n.currentOperator.providers, function(n) {
                                return n.id
                            }) : ""
                        })
                    })
                },
                o = function() {
                    var t = r.find("#doctors").data("kendoMultiSelect").value(),
                        i;
                    t && t.length > 0 ? (i = _.map(t, function(n) {
                        return {
                            id: n
                        }
                    }), n.currentOperator.providers = i) : n.currentOperator.providers = null
                },
                s = function() {
                    r.find("#practiceForm").valid() && (o(), n.saveOperator())
                };
            (function() {
                n.save = s;
                f();
                n.$watch("isInitDoctor", function() {
                    n.isInitDoctor && e()
                })
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceSettingView", ["$log", "$timeout", "$modal", "$state", "appNav", "enums", "eventAggregator", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/practice-setting-view.html",
        scope: {},
        link: function(n) {
            var t = function(n) {
                    u.switchState(n, i)
                },
                i = function() {
                    var t = n.patientId;
                    return {
                        patientId: t
                    }
                };
            (function() {
                n.switchState = t
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemconfigBorwserView", ["$log", "$timeout", "$filter", "$window", "appNav", "enums", "permissionProvider", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/practice-systemconfig-borwser-view.html",
        scope: {
            officeId: "="
        },
        link: function(n) {
            var t = function(n) {
                u.goToState(n)
            };
            (function() {
                n.switchState = t;
                t("systemconfigBrowser.emr")
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemsettingApptTypeEditView", ["$log", "$timeout", "aresDialog", function(n, t, i) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-systemsetting-appt-type-edit-view.html",
        link: function(n, r) {
            var u = function() {
                    var u = 5,
                        t = $("#div_color"),
                        i, f;
                    $(t).css("background-color", "inherit");
                    $('<input id="colorInput" type="color" />').appendTo(t).kendoColorPicker({
                        tileSize: 45,
                        columns: u,
                        palette: n.colorValues,
                        open: function() {
                            for (var e, i, f = $(".k-palette"), r = f.find("td.k-item"), t = 0; t < n.procedureColors.length; t++) $(r[t]).addClass("color-cell").html(n.procedureColors[t].name), $(r[t]).css({
                                "text-align": "center",
                                "font-size": "xx-small",
                                color: "black"
                            });
                            if (e = n.procedureColors.length, i = $(r[e]), !i.hasClass("non-color") && (i.addClass("non-color"), i.css("text-align", "center"), n.colorValues.length != n.procedureColors.length)) {
                                var o = Math.floor((n.procedureColors.length + u - 1) / u - 1),
                                    s = f.find("tr:eq(" + o + ")"),
                                    h = '<tr><td style="text-align:center" colspan="' + u + '">-----自定义颜色-----<\/td><\/tr>';
                                $(h).insertAfter(s)
                            }
                        }
                    });
                    $('<input id="colorInput2" type="color" />').appendTo(t).kendoColorPicker({
                        buttons: !0,
                        open: function() {
                            var n = $(t).find("#colorInput").data("kendoColorPicker").value();
                            this.value(n)
                        },
                        change: function(n) {
                            var i = n.value;
                            $(t).find("#colorInput").data("kendoColorPicker").value(i)
                        }
                    });
                    i = $(t).find(".k-colorpicker");
                    i.css("display:inline");
                    i.width(20);
                    $(i[0]).width(170);
                    f = $(i[1]).find(".k-i-arrow-s");
                    f.removeClass("k-i-arrow-s").removeClass("k-icon");
                    f.addClass("glyphicon").addClass("glyphicon-wrench");
                    $(t).find(".k-selected-color").css({
                        width: "100%",
                        height: "2.25em"
                    });
                    r.find("#div_color").find("#colorInput").data("kendoColorPicker").value(n.systemseting.itemValue)
                },
                f = function() {
                    if (!n.systemseting.itemName) {
                        i.info("提示", "名称不能为空!");
                        return
                    }
                    if (n.systemseting.itemName == "其他") {
                        i.info("提示", "名称不能为:其他!");
                        return
                    }
                    var t = r.find("#div_color").find("#colorInput").data("kendoColorPicker").value();
                    n.systemseting.itemValue = t;
                    (t == "#ffffff" || t == "#FFFFFF" || t == "transparent") && (n.systemseting.itemValue = null);
                    n.save()
                };
            (function() {
                n.saveCheck = f;
                n.$watch("systemseting", function() {
                    n.systemseting && u()
                });
                t(function() {
                    Ares.centerModal(r.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
patientModule.directive("practiceSystemsettingApptTypeView", ["$log", "$timeout", "$window", "$compile", function(n, t, i, r) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-systemsetting-appt-type-view.html",
        controller: "PracticeSystemsettingApptTypeCtrl",
        link: function(n, t) {
            var s = Ares.kendoGridUtil(i, n),
                u = null,
                h = function() {
                    var n = this.dataSource.data();
                    t.find("#systemsettingList table tbody tr").each(function(t, i) {
                        var u = n[t],
                            r = $("td.cell-command", i).children().find("button").eq(0),
                            f;
                        u.isInactive ? ($(r).attr("title", "启用"), $(r).text("启用")) : ($(r).attr("title", "禁用"), $(r).text("禁用"));
                        u.isDefault && (f = $("td.cell-command", i).find('button[data-action="delete"]'), f.remove())
                    })
                },
                f = function() {
                    var i = $(t).find("#systemsettingList");
                    r(i)(n)
                },
                c = function() {
                    var i = $(t).find("#systemsettingList");
                    u = i.kendoGrid({
                        dataSource: n.systemsettings,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        dataBound: h,
                        columns: [{
                            field: "displayOrder",
                            title: "序号",
                            width: "50px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "itemName",
                            title: "名称",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "itemValue",
                            title: "颜色",
                            width: "100px",
                            attributes: {
                                style: "background-color: #=itemValue#;"
                            },
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            },
                            template: ""
                        }, {
                            field: "isInactiveStr",
                            title: "是否启用",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "isDefaultStr",
                            title: "属性",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            template: s.commandTemplate,
                            title: "",
                            width: "150px",
                            attributes: {
                                "class": "cell-command",
                                "ares-hide-when-parent": "Appointment"
                            },
                            headerAttributes: {
                                "ares-hide-when-parent": "Appointment"
                            }
                        }]
                    }).data("kendoGrid");
                    f()
                },
                e = function() {
                    u ? (u.dataSource.data(n.systemsettings), f()) : c()
                },
                o = function() {
                    var t = u.select();
                    n.selectedRowIndex = $("tr", u.tbody).index(t)
                },
                l = function() {
                    o();
                    var i = n.systemsettings[n.selectedRowIndex],
                        t = n.systemsettings[n.selectedRowIndex - 1];
                    t && n.upItem(i, t)
                },
                a = function() {
                    o();
                    var i = n.systemsettings[n.selectedRowIndex],
                        t = n.systemsettings[n.selectedRowIndex + 1];
                    t && n.downItem(i, t)
                },
                v = function(t) {
                    u.dataSource.data(n.systemsettings);
                    u.select("#systemsettingList tr:eq(" + (t - 1) + ")")
                },
                y = function(t) {
                    u.dataSource.data(n.systemsettings);
                    u.select("#systemsettingList tr:eq(" + (t + 1) + ")")
                },
                p = [{
                    text: "开启",
                    action: "isInEnable"
                }, {
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "删除",
                    action: "delete",
                    icon: "glyphicon-remove"
                }, ],
                w = function(t) {
                    return _.find(n.systemsettings, function(n) {
                        return n.id == t
                    })
                },
                b = function(t, i, r) {
                    var u = w(r);
                    switch (i) {
                        case "isInEnable":
                            n.isEnable(u);
                            break;
                        case "update":
                            n.openEditDialog(u);
                            break;
                        case "delete":
                            n.deleteSystemSetting(u);
                            e()
                    }
                };
            (function() {
                n.up = l;
                n.down = a;
                n.refreshUpDownGrid = v;
                n.refreshDownGrid = y;
                n.commands = p;
                n.onCommandClick = b;
                n.$watch("systemsettings", function() {
                    n.systemsettings && e()
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemsettingBrowserView", ["$log", "$compile", "$timeout", "$window", "permissionProvider", function(n, t, i, r, u) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-systemsetting-browser-view.html",
        controller: "PracticeSystemSettingBrowserCtrl",
        scope: {
            parentItem: "@"
        },
        link: function(n, i) {
            var h = Ares.kendoGridUtil(r, n),
                f = null,
                c = function() {
                    var r = this.dataSource.data(),
                        t;
                    i.find("#systemsettingList table tbody tr").each(function(n, t) {
                        var i = r[n];
                        i.isDefault && $("td.cell-command", t).children().remove()
                    });
                    n.systemsettingList.length > 0 && (t = n.systemsettingList[0].itemType, t == "患者来源" && $("#systemsettingList tr").each(function() {
                        ($(this).find("td").eq(1).text() == "朋友介绍" || $(this).find("td").eq(1).text() == "员工介绍") && ($(this).find("td").eq(2).find("button").prop("disabled", !0), $(this).find("td").eq(2).find("button").addClass("k-state-disabled"))
                    }))
                };
            n.initList = function() {
                var t = [{
                        field: "index",
                        title: "序号",
                        width: "50px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, {
                        field: "itemName",
                        title: "名称",
                        width: "300px",
                        headerAttributes: {
                            style: "text-align: center; font-size: 14px; font-weight: bolder;"
                        }
                    }, ],
                    r;
                t.push({
                    hidden: !0,
                    field: "itemValue",
                    title: "说明",
                    width: "300px",
                    headerAttributes: {
                        style: "text-align: center; font-size: 14px; font-weight: bolder;"
                    }
                });
                t.push({
                    hidden: !0,
                    field: "itemCode",
                    title: "标准科室分类代码",
                    width: "300px",
                    headerAttributes: {
                        style: "text-align: center; font-size: 14px; font-weight: bolder;"
                    }
                });
                n.settingTypeInfo && (!n.settingTypeInfo.isChargeItemSetting || n.settingTypeInfo.isChargeItemSetting && n.isChargeItemEditAllowed) && t.push({
                    template: h.commandTemplate,
                    title: "",
                    width: "150px",
                    attributes: {
                        "class": "cell-command"
                    }
                });
                n.systemsettingList && (r = $(i).find("#systemsettingList"), f = r.kendoGrid({
                    dataSource: n.systemsettingList,
                    scrollable: !1,
                    sortable: !1,
                    selectable: "single",
                    dataBound: c,
                    columns: t
                }).data("kendoGrid"), e(), n.systemSettingGrid = f)
            };
            var e = function() {
                    var r = $(i).find("#systemsettingList");
                    n.settingTypeInfo.isChargeItemSetting ? $(r).find('button[title="删除"]').attr("ares-hide-when-parent", "ChargeItem") : n.settingTypeInfo.isPatientInfoSetting ? $(r).find('button[title="删除"]').attr("ares-hide-when-parent", "PatientInfo") : n.settingTypeInfo.isAppointmentSetting ? $(r).find('button[title="删除"]').attr("ares-hide-when-parent", "Appointment") : n.settingTypeInfo.isDepartmentSetting && ($(r).find('button[title="删除"]').attr("ares-hide-when-connect-hrp", "Department"), $(r).find('button[title="修改"]').attr("ares-hide-when-connect-hrp", "Department"));
                    t(r)(n)
                },
                o = function() {
                    f ? (f.dataSource.data(n.systemsettingList), e()) : n.initList()
                },
                s = function() {
                    var t = f.select();
                    n.selectedRowIndex = $("tr", f.tbody).index(t)
                },
                l = function() {
                    s();
                    var i = n.systemsettingList[n.selectedRowIndex],
                        t = n.systemsettingList[n.selectedRowIndex - 1];
                    t && n.upItem(i, t)
                },
                a = function() {
                    s();
                    var i = n.systemsettingList[n.selectedRowIndex],
                        t = n.systemsettingList[n.selectedRowIndex + 1];
                    t && n.downItem(i, t)
                },
                v = function(t) {
                    f.dataSource.data(n.systemsettingList);
                    f.select("#systemsettingList tr:eq(" + (t + 1) + ")")
                },
                y = function(t) {
                    f.dataSource.data(n.systemsettingList);
                    f.select("#systemsettingList tr:eq(" + (t + 2) + ")")
                },
                p = [{
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "删除",
                    action: "delete",
                    icon: "glyphicon-remove"
                }, ],
                w = function(t) {
                    return _.find(n.systemsettingList, function(n) {
                        return n.id == t
                    })
                },
                b = function(t, i, r) {
                    var u = w(r);
                    switch (i) {
                        case "update":
                            n.editSystemSettingItem(u);
                            break;
                        case "delete":
                            n.deleteSystemSettingItem(u);
                            o()
                    }
                },
                k = function() {
                    var n = $(window).height() - 200;
                    $("#itemlist").css("height", n)
                };
            (function() {
                n.$watch("systemsettingList", function() {
                    o()
                });
                k();
                n.up = l;
                n.down = a;
                n.commands = p;
                n.onCommandClick = b;
                n.refreshUpDownGrid = v;
                n.refreshDownGrid = y;
                n.isChargeItemEditAllowed = u.isChargeItemEditAllowed
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemsettingEditView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-systemsetting-edit-view.html",
        link: function(n, i) {
            var r, u = function() {
                    r = Ares.validateForm(i.find("#ruleSettingForm"), {
                        itemName: {
                            required: !0,
                            systemSettingName: !0,
                            maxlength: 20
                        }
                    }, {
                        itemName: {
                            required: "请输入项目名称",
                            systemSettingName: "名称已被使用",
                            maxlength: "项目名称不能超过20个字符"
                        }
                    })
                },
                f = function() {
                    i.find("#ruleSettingForm").valid() && n.saveSystemSettingItem()
                };
            (function() {
                u();
                n.validAndSave = f;
                n.$watch("currentSystemSettingItem", function() {
                    r && Ares.clearError(i.find("#ruleSettingForm"))
                });
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemsettingTransactioncodeEditView", ["$log", "$timeout", "aresDialog", function(n, t, i) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-systemsetting-transactioncode-edit-view.html",
        link: function(n, r) {
            var u = function() {
                    var u = 9,
                        t = $("#div_color"),
                        i, f;
                    $(t).css("background-color", "inherit");
                    $('<input id="colorInput" type="color" />').appendTo(t).kendoColorPicker({
                        tileSize: 45,
                        columns: u,
                        palette: n.colorValues,
                        open: function() {
                            for (var e, i, f = $(".k-palette"), r = f.find("td.k-item"), t = 0; t < n.procedureColors.length; t++) $(r[t]).addClass("color-cell").html(n.procedureColors[t].name), $(r[t]).css({
                                "text-align": "center",
                                "font-size": "xx-small",
                                color: "black"
                            });
                            if (e = n.procedureColors.length, i = $(r[e]), !i.hasClass("non-color") && (i.addClass("non-color"), i.css("text-align", "center"), i.html("无"), n.colorValues.length != n.procedureColors.length)) {
                                var o = Math.floor((n.procedureColors.length + u - 1) / u - 1),
                                    s = f.find("tr:eq(" + o + ")"),
                                    h = '<tr><td style="text-align:center" colspan="' + u + '">-----自定义颜色-----<\/td><\/tr>';
                                $(h).insertAfter(s)
                            }
                        }
                    });
                    $('<input id="colorInput2" type="color" />').appendTo(t).kendoColorPicker({
                        buttons: !0,
                        open: function() {
                            var n = $(t).find("#colorInput").data("kendoColorPicker").value();
                            this.value(n)
                        },
                        change: function(n) {
                            var i = n.value;
                            $(t).find("#colorInput").data("kendoColorPicker").value(i)
                        }
                    });
                    i = $(t).find(".k-colorpicker");
                    i.css("display:inline");
                    i.width(20);
                    $(i[0]).width(170);
                    f = $(i[1]).find(".k-i-arrow-s");
                    f.removeClass("k-i-arrow-s").removeClass("k-icon");
                    f.addClass("glyphicon").addClass("glyphicon-wrench");
                    $(t).find(".k-selected-color").css({
                        width: "100%",
                        height: "2.25em"
                    });
                    r.find("#div_color").find("#colorInput").data("kendoColorPicker").value(n.transactioncode.color)
                },
                f = function() {
                    if (!n.transactioncode.name) {
                        i.info("提示", "名称不能为空!");
                        return
                    }
                    var t = r.find("#div_color").find("#colorInput").data("kendoColorPicker").value();
                    n.transactioncode.color = t;
                    (t == "#ffffff" || t == "#FFFFFF" || t == "transparent") && (n.transactioncode.color = null);
                    n.save()
                },
                e = function() {
                    r.find("#div_category").kendoComboBox({
                        dataSource: n.categories,
                        dataTextField: "itemName",
                        dataValueField: "itemName",
                        value: n.transactioncode.category,
                        select: function(i) {
                            var r = this;
                            t(function() {
                                n.transactioncode.category = r.dataItem(i.item)[r.options.dataValueField] || "其它"
                            })
                        }
                    })
                };
            (function() {
                n.saveCheck = f;
                n.$watch("transactioncode", function() {
                    n.transactioncode && u()
                });
                n.$watch("categories", function() {
                    n.categories && e()
                });
                t(function() {
                    Ares.centerModal(r.closest(".modal-dialog"))
                }, 5)
            })()
        }
    }
}]);
patientModule.directive("practiceSystemsettingTransactioncodeView", ["$log", "$timeout", "$window", "$compile", function(n, t, i, r) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-systemsetting-transactioncode-view.html",
        controller: "PracticeSystemsettingTransactioncodeCtrl",
        link: function(n, t) {
            var e = Ares.kendoGridUtil(i, n),
                u = null,
                f = null,
                s;
            n.initList = function() {
                if (n.transactioncodes) {
                    var i = $(t).find("#currentChargeItemCatagory");
                    u = i.kendoGrid({
                        dataSource: n.transactioncodes,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        columns: [{
                            field: "seqNum",
                            title: "编号",
                            width: "50px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "name",
                            title: "名称",
                            width: "300px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "color",
                            title: "颜色",
                            width: "100px",
                            attributes: {
                                style: "background-color: #=color#;"
                            },
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            },
                            template: ""
                        }, {
                            template: e.commandTemplate,
                            title: "",
                            width: "150px",
                            attributes: {
                                "ares-hide-when-parent": "Appointment"
                            },
                            headerAttributes: {
                                "ares-hide-when-parent": "Appointment"
                            }
                        }]
                    }).data("kendoGrid")
                }
            };
            var h = function() {
                    u ? u.dataSource.data(n.transactioncodes) : n.initList();
                    u && r(u.element)(n)
                },
                o = function() {
                    var t = u.select();
                    n.selectedRowIndex = $("tr", u.tbody).index(t)
                },
                c = function() {
                    o();
                    var i = n.transactioncodes[n.selectedRowIndex],
                        t = n.transactioncodes[n.selectedRowIndex - 1];
                    t && n.upItem(i, t)
                },
                l = function() {
                    o();
                    var i = n.transactioncodes[n.selectedRowIndex],
                        t = n.transactioncodes[n.selectedRowIndex + 1];
                    t && n.downItem(i, t)
                },
                a = function(t) {
                    u.dataSource.data(n.transactioncodes);
                    u.select("#currentChargeItemCatagory tr:eq(" + (t - 1) + ")")
                },
                v = function(t) {
                    u.dataSource.data(n.transactioncodes);
                    u.select("#currentChargeItemCatagory tr:eq(" + (t + 1) + ")")
                },
                y = [{
                    text: "修改",
                    action: "update",
                    icon: "glyphicon-pencil"
                }, {
                    text: "删除",
                    action: "delete",
                    icon: "glyphicon-remove"
                }, ],
                p = function(t) {
                    return _.find(n.transactioncodes, function(n) {
                        return n.id == t
                    })
                },
                w = function(t, i, r) {
                    var u = p(r);
                    switch (i) {
                        case "update":
                            n.openEditDialog(u);
                            break;
                        case "delete":
                            n.destroy(r)
                    }
                };
            n.initAllList = function() {
                if (n.transactioncodes) {
                    var i = $(t).find("#allCurrentChargeItemCatagory");
                    f = i.kendoGrid({
                        dataSource: n.transactioncodes,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        columns: [{
                            field: "seqNum",
                            title: "编号",
                            width: "50px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "name",
                            title: "名称",
                            width: "150px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "category",
                            title: "所属大类",
                            width: "150px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "color",
                            title: "颜色",
                            width: "100px",
                            attributes: {
                                style: "background-color: #=color#;"
                            },
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            },
                            template: ""
                        }, {
                            template: e.commandTemplate,
                            title: "",
                            width: "150px",
                            attributes: {
                                "ares-hide-when-parent": "Appointment"
                            },
                            headerAttributes: {
                                "ares-hide-when-parent": "Appointment"
                            }
                        }]
                    }).data("kendoGrid");
                    r(i)(n)
                }
            };
            n.exportExcel = function() {
                f && f.saveAsExcel()
            };
            s = function() {
                    var n = $(window).height() - 220;
                    t.find("#itemlist").css("height", n);
                    t.find("#tablelist").css("height", n + 20);
                    t.find("#tablealllist").css("height", n + 20)
                },
                function() {
                    s();
                    n.$watch("transactioncodes", function() {
                        n.isAllCharge ? n.initAllList() : h()
                    });
                    n.up = c;
                    n.down = l;
                    n.commands = y;
                    n.onCommandClick = w;
                    n.refreshUpDownGrid = a;
                    n.refreshDownGrid = v
                }()
        }
    }
}]);
patientModule.directive("practiceTxplanItemCodeConfigView", ["$log", "$timeout", "aresDialog", "practiceSvc", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-txplan-item-code-config-view.html",
        link: function(n, i) {
            (function() {})();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceTxplanItemEditView", ["$log", "$timeout", "aresDialog", "practiceSvc", function(n, t, i, r) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/practice-txplan-item-edit-view.html",
        link: function(n, i) {
            var u = function() {
                r.getDiagnoseItemList().success(function(t) {
                    n.txPlan && i.find("#txPlanDiagnose").kendoMultiSelect({
                        dataTextField: "itemName",
                        dataValueField: "id",
                        dataSource: t,
                        value: n.txPlan.diagnoseItem
                    })
                })
            };
            (function() {
                n.$watch("txPlan", function() {
                    n.txPlan && u()
                })
            })();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceTxplanItemPlanView", ["$log", "$timeout", "$window", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/practice-txplan-item-plan-view.html",
        link: function(n, r) {
            var f = null,
                e = function() {
                    var t = this;
                    $(r).find("#itemGrid table tbody tr").each(function(i, r) {
                        var u = t.dataItem(r),
                            f = _.find(n.giftPlanList, function(n) {
                                return n.itemName == u.itemName ? !0 : !1
                            });
                        f ? $("td.cell-command", r).find('button[data-action="add"]').remove() : $("td.cell-command", r).find('button[data-action="remove"]').remove()
                    })
                },
                o = function() {
                    var u = Ares.kendoGridUtil(i, n),
                        t;
                    n.chargeCatagoryList && (t = r.find("#itemGrid"), t.html(""), f = t.kendoGrid({
                        dataSource: {
                            data: n.chargeItemListFilteResult
                        },
                        height: 500,
                        sortable: !0,
                        selectable: "single",
                        dataBound: e,
                        columns: [{
                            field: "itemName",
                            title: "名称",
                            width: "150px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "procedureCode",
                            title: "编码",
                            width: "80px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "unit",
                            title: "单位",
                            width: "50px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            field: "price",
                            title: "单价",
                            width: "50px",
                            attributes: {
                                "class": "cell-left"
                            }
                        }, {
                            template: u.commandTemplate,
                            title: "",
                            width: "60px",
                            attributes: {
                                "class": "cell-command"
                            }
                        }]
                    }).data("kendoGrid"))
                },
                s = [{
                    text: "添加处置",
                    action: "add",
                    icon: "glyphicon-plus"
                }, {
                    text: "取消",
                    action: "remove",
                    icon: "glyphicon-minus"
                }],
                h = function(t) {
                    return _.find(n.chargeItemList, function(n) {
                        return n.id == t
                    })
                },
                c = function(t, i, r) {
                    n.$apply(function() {
                        var t = h(r),
                            u = {
                                id: t.id,
                                itemName: t.itemName,
                                itemId: t.id,
                                price: t.price,
                                count: 1
                            };
                        switch (i) {
                            case "add":
                                n.add(u);
                                break;
                            case "remove":
                                n.remove(u)
                        }
                    })
                },
                u = function() {
                    f ? n.chargeItemListFilteResult ? f.dataSource.data(n.chargeItemListFilteResult) : f.dataSource.data([]) : o()
                },
                l = function(t) {
                    var i = _.find(n.giftPlanList, function(n) {
                        return n.itemName == t.itemName ? !0 : !1
                    });
                    i ? alert("a") : (n.giftPlanList.push(t), u())
                },
                a = function(t) {
                    var i = _.findIndex(n.giftPlanList, function(n) {
                        return n.itemName == t.itemName ? !0 : !1
                    });
                    i > -1 && (n.giftPlanList.splice(i, 1), u())
                },
                v = function() {
                    n.chargeItemsFilter = "";
                    n.resetChargeItemList(null, n.defaultSupCategoryId)
                },
                y = function() {
                    n.chargeItemsFilter = "";
                    n.resetChargeItemList(n.defaultCategoryId)
                },
                p = function() {
                    n.chargeItemListFilteResult = n.chargeItemsFilter ? n.chargeItemList.filter(function(t) {
                        return t.itemName.indexOf(n.chargeItemsFilter) > -1 || t.pinyin && t.pinyin.indexOf(n.chargeItemsFilter) > -1
                    }) : angular.copy(n.chargeItemList);
                    u()
                };
            (function() {
                n.commands = s;
                n.onCommandClick = c;
                n.add = l;
                n.remove = a;
                n.onHandleTypeSelected = y;
                n.onHandleSupCategorySelect = v;
                n.chargeItemsFilter = "";
                n.filteChargeItemByFilter = p;
                n.$watch("chargeItemList", function() {
                    n.chargeItemListFilteResult = angular.copy(n.chargeItemList);
                    u()
                });
                n.$watch("selectHandleItem", function() {
                    n.selectHandleItem == !0 && (n.selectHandleCatagory = 0, n.chargeCatagoryList.length > 0 && (n.selectHandleCatagory = n.chargeCatagoryList[0].id, u()))
                })
            })();
            t(function() {
                Ares.centerModal(r.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceTxplanItemView", ["$log", "$timeout", "$window", "officeUtil", function(n, t, i, r) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/practice-txplan-item-view.html",
        controller: "PracticeTxplanItemCtrl",
        link: function(n, t) {
            var e = Ares.kendoGridUtil(i, n),
                u = null,
                o = function() {
                    var i = $(t).find("#systemsettingList"),
                        r = $(window).height() - 255 - (window.Ares3 ? 20 : 0);
                    u = i.kendoGrid({
                        dataSource: n.txPlanList,
                        height: r,
                        scrollable: !1,
                        sortable: !1,
                        selectable: "single",
                        columns: [{
                            field: "code",
                            title: "项目代码",
                            width: "50px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "name",
                            title: "项目名称",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "isInactiveStr",
                            title: "是否启用",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "price",
                            title: "费用",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            field: "notes",
                            title: "备注",
                            width: "100px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            }
                        }, {
                            template: e.commandTemplate,
                            title: "操作",
                            width: "80px",
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight: bolder;"
                            },
                            attributes: {
                                "class": "cell-command"
                            }
                        }]
                    }).data("kendoGrid")
                },
                f = function() {
                    u ? u.dataSource.data(n.txPlanList) : o()
                },
                s = function() {
                    r.isParentEnabled("ChargeItem").then(function(t) {
                        n.isChargeItemParentEnabled = t;
                        var i = [{
                            text: "修改",
                            action: "update",
                            icon: "glyphicon-pencil"
                        }];
                        n.isChargeItemParentEnabled || i.push({
                            text: "删除",
                            action: "delete",
                            icon: "glyphicon-remove"
                        });
                        n.commands = i
                    })
                },
                h = function(t) {
                    return _.find(n.txPlanList, function(n) {
                        return n.id == t
                    })
                },
                c = function(t, i, r) {
                    var u = h(r);
                    switch (i) {
                        case "update":
                            n.openEditDialog(r);
                            break;
                        case "delete":
                            n.deleteTxPlan(u);
                            f()
                    }
                };
            (function() {
                s();
                n.onCommandClick = c;
                n.$watch("txPlanList", function() {
                    n.txPlanList && f()
                })
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryCell", ["$log", "$timeout", "apptInventorySvc", "loginContext", "aresNotification", "aresDialog", function(n, t, i, r, u, f) {
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-cell.html",
        scope: {
            dayOfWeek: "@",
            templateAmount: "=",
            editable: "=",
            isShowEditButton: "=",
            dailyAmount: "=",
            isDayInventory: "=",
            focusOnSave: "=",
            error: "=",
            selectedService: "="
        },
        link: function(r, u) {
            r.backUpAmount = {};
            var o = function() {
                    r.isShowEditButton = r.editable ? !1 : !0
                },
                s = function() {
                    r.editable = !0;
                    r.isShowEditButton = !1;
                    c();
                    r.isDayInventory ? angular.copy(r.dailyAmount, r.backUpAmount) : angular.copy(r.templateAmount, r.backUpAmount)
                },
                h = function() {
                    r.editable = !1;
                    r.isDayInventory ? r.dailyAmount.displayAmount = r.backUpAmount.displayAmount : r.templateAmount.amount = r.backUpAmount.amount
                },
                c = function() {
                    t(function() {
                        u.find("#uxAmountValue").focus()
                    }, 200)
                },
                l = function() {
                    if (!/^\d+$/.test(r.templateAmount.amount)) return r.error = !0, f.info("信息", "模板库存数量为非负整数!"), !1;
                    if (r.templateAmount.amount < 0) return r.error = !0, f.info("信息", "模板库存数量不能小于0!"), !1;
                    i.saveTemplate(r.templateAmount).success(function(n) {
                        n <= 0 ? (r.error = !0, f.info("信息", "渠道库存模板数据保存失败!")) : (r.editable = !1, r.templateAmount.id = n)
                    }).error(function(t) {
                        n.log(t);
                        r.error = !0;
                        f.info("信息", "渠道库存模板数据保存失败!!")
                    })
                },
                a = function() {
                    if (!/^\d+$/.test(r.dailyAmount.displayAmount)) return r.error = !0, f.info("信息", "模板库存数量为非负整数!"), !1;
                    if (r.dailyAmount.displayAmount < 0) return f.info("信息", "库存数量不能小于0!"), r.error = !0, !1;
                    if (r.dailyAmount.displayAmount < r.dailyAmount.appliedAmount) return f.info("信息", "库存数量不能小于已经预约数量!"), r.error = !0, !1;
                    r.dailyAmount.amount = r.dailyAmount.displayAmount;
                    i.saveDailyInventory(r.dailyAmount).success(function(n) {
                        n <= 0 ? (r.error = !0, f.info("信息", "渠道库存模板数据保存失败!")) : (r.editable = !1, r.dailyAmount.id = n, r.dailyAmount.hasCreated = !0)
                    }).error(function(t) {
                        n.log(t);
                        r.error = !0;
                        f.info("信息", "渠道库存模板数据保存失败!!")
                    })
                },
                e = function() {
                    r.isDayInventory ? a() : l()
                },
                v = function() {
                    if (!r.focusOnSave) return !1;
                    e()
                },
                y = function() {
                    r.isShowEditButton = !1
                },
                p = function(n) {
                    r.focusOnSave = n
                };
            (function() {
                r.save = e;
                r.cancel = h;
                r.edit = s;
                r.focusSave = v;
                r.setFocusValue = p;
                r.hideEditButton = y;
                r.showEditButton = o
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryHomeView", ["$log", "$timeout", "$filter", "$window", "appNav", "permissionProvider", "dataDicSvc", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-home-view.html",
        link: function(n) {
            var t = function() {
                    var t = [new Ares.TabItem("setting.apptInventory.baseSetting", "渠道基础配置", "glyphicon glyphicon-cog", null), new Ares.TabItem("setting.apptInventory.itemMapping", "渠道服务项目映射", "glyphicon glyphicon-cog", null), new Ares.TabItem("setting.apptInventory.inventorySetting", "渠道库存配置", "glyphicon glyphicon-cog", null)];
                    n.states = t
                },
                i = function() {
                    return n.enabledChannels && n.enabledChannels.length > 0 ? !0 : !1
                },
                r = function() {
                    e.enabledChannelsDic.load().then(function(i) {
                        n.enabledChannels = i;
                        t()
                    })
                };
            (function() {
                n.enabledChannels = [];
                n.canConfigApptInventory = i;
                r()
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryItemsBaseSettingView", ["$timeout", "aresDialog", "moduleOptionProvider", function() {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "ApptInventoryItemsBaseSettingCtrl",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-items-base-setting-view.html",
        link: function(n) {
            var t = "",
                i = function() {
                    n.isEdit = !0
                },
                r = function(t) {
                    t.$valid && (n.saveApptInventorysBaseSetting(), n.isEdit = !1)
                },
                u = function(t) {
                    t.$invalid && (t.openDayOffset.$invalid && (n.baseSetting.openDayOffset = n.baseSettingCache.openDayOffset), t.openDayCount.$invalid && (n.baseSetting.openDayCount = n.baseSettingCache.openDayCount));
                    n.isEdit = !1
                };
            (function() {
                n.editBaseSetting = i;
                n.saveBaseSetting = r;
                n.cancelBaseSetting = u;
                n.selectedService = t;
                n.$watch("selectedService", function(t) {
                    t !== "" && n.initApptInventorysBaseSetting(t)
                })
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryItemsMappingView", ["$log", "$modal", "$timeout", "aresDialog", "gridOptionUtil", "kendoUtil", "$window", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        controller: "ApptInventoryItemsMappingCtrl",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-items-mapping-view.html",
        link: function(n, t) {
            var u = 1,
                s = "",
                o = {},
                h = function(t) {
                    u ? (n.apptItem = t, f(n.apptItem), n.selectedChannelId = t.id, n.isEdit = !1) : r.info("提示", "切换其他项目前先完成本项目的操作")
                },
                f = function(n) {
                    n.itemProviders.length === 0 && n.itemProviders.push({
                        maxApptNumber: "",
                        providerId: "",
                        providerName: "未指定医生"
                    })
                },
                c = function(t) {
                    t.providerId > 0 ? (n.apptItem.itemProviders.push({
                        maxApptNumber: "",
                        providerId: "",
                        providerName: ""
                    }), u = 0) : r.info("提示", "请选择关联医生")
                },
                l = function(t) {
                    n.apptItem.itemProviders.splice(t, 1)
                },
                a = function() {
                    n.isEdit = !0;
                    o = angular.copy(n.apptItem)
                },
                v = function() {
                    var o = n.apptItem.itemProviders,
                        t = [],
                        f = !0,
                        e = !0,
                        s = /^(([1-9][0-9]+|[1-9])(\\.[0-9]+)?|\\.[0-9]+|)$/,
                        i;
                    if (angular.forEach(o, function(n) {
                            var i = {
                                providerId: n.providerId,
                                maxApptNumber: n.maxApptNumber
                            };
                            s.test(n.maxApptNumber) || (e = !1);
                            n.maxApptNumber == "" ? i.maxApptNumber = -1 : n.maxApptNumber;
                            n.providerId >= 0 ? t.push(i) : f = !1
                        }), !f) {
                        r.info("提示", "请选择关联医生或刪除未关联医生项");
                        return
                    }
                    if (!e) {
                        r.info("提示", "可约数量必须为正整数或为空");
                        return
                    }
                    i = {
                        id: n.apptItem.id,
                        isUnavailableByHour: n.apptItem.isUnavailableByHour,
                        isUnavailableByHalfhour: n.apptItem.isUnavailableByHalfhour,
                        itemProviders: t
                    };
                    t.length == 0 ? r.confirm("提示", "确认保存该服务项目为未指定医生").then(function() {
                        n.updateApptInventoryItem(i, n.selectedService)
                    }) : n.updateApptInventoryItem(i, n.selectedService);
                    u = 1
                },
                y = function() {
                    n.apptItem = angular.copy(_.find(n.apptItemsCache, function(t) {
                        return t.id === n.selectedChannelId
                    }));
                    n.apptItem && f(n.apptItem);
                    n.apptItem = o;
                    n.isEdit = !1;
                    u = 1
                },
                p = function(t) {
                    var i = !1;
                    return angular.forEach(n.apptItem.itemProviders, function(n) {
                        t == n.providerId && (i = !0)
                    }), i
                },
                w = function(n, u, f) {
                    i(function() {
                        var i = t.find("#" + n),
                            e = i.kendoDropDownList({
                                dataSource: u,
                                optionLabel: " ",
                                dataTextField: "name",
                                dataValueField: "id",
                                value: f,
                                filter: "contains",
                                select: function(n) {
                                    f = this.dataItem(n.item)[this.options.dataValueField] || null;
                                    var t = p(f);
                                    t && (r.info("提示", "该医生已经被关联，请选择其他医生"), n.preventDefault())
                                }
                            }).data("kendoDropDownList")
                    })
                },
                b = function(t, i) {
                    n.apptItem.itemProviders.length > 1 && parseInt(t) === 0 ? r.confirm("提示", "选择“全部”将清除其他已配置项").then(function() {
                        var t = n.apptItem.itemProviders[i];
                        t.maxApptNumber = "";
                        n.apptItem.itemProviders = [t]
                    }, function() {
                        n.apptItem.itemProviders[i].providerId = -1;
                        $("#" + i).data("kendoDropDownList").select(-1)
                    }) : n.apptItem.itemProviders.length === 1 && parseInt(t) === 0 && (n.apptItem.itemProviders[i].maxApptNumber = "")
                },
                k = function() {
                    var n = angular.element(e.document).height() - 112,
                        r = t.find(".deduction-plan-list-wrap"),
                        u = r.find(".deduction-plan-list");
                    u.height(n - 40);
                    r.height(n);
                    i(function() {
                        var n = t.find(".deduction-icon");
                        n.tooltip();
                        t.find(".mCustomScrollBox").css("overflow", "visible");
                        t.find(".mCSB_container").css("overflow", "visible")
                    }, 800)
                };
            (function() {
                n.changeChannel = h;
                n.editDianPing = a;
                n.saveDianPing = v;
                n.addDianPingItem = c;
                n.cancelEditDianPing = y;
                n.removeDianPingItem = l;
                n.initDrop = w;
                n.checkApptItemLength = f;
                n.onDoctorSelected = b;
                n.selectedService = s;
                k();
                n.$watch("selectedService", function(t) {
                    t !== "" && n.updateItems(t)
                })
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryItemsSettingView", ["$log", "$modal", "$q", "$window", "$timeout", "apptInventorySvc", "aresDialog", "aresNotification", function(n, t) {
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-items-setting-view.html",
        controller: "ApptInventoryItemsSettingCtrl",
        link: function(n) {
            var i = "",
                r = function() {
                    var i = t.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<appt-inventoy-items-setting-reset-view><\/appt-inventoy-items-setting-reset-view>",
                        size: "sm",
                        controller: "ApptInventoyItemsSettingResetCtrl",
                        resolve: {
                            host: function() {
                                return {
                                    service: n.selectedService
                                }
                            }
                        }
                    }).result;
                    i.then(function() {
                        n.initApptInventoryTemplates(n.selectedService)
                    })
                };
            (function() {
                n.selectedService = i;
                n.resetAllInventoryItem = r;
                n.$watch("selectedService", function(t) {
                    t !== "" && n.isDayInventory ? n.initApptInventorys(t) : t === "" || n.isDayInventory || n.initApptInventoryTemplates(t)
                })
            })()
        }
    }
}]);
practiceModule.directive("apptInventoryServiceList", ["$log", "$timeout", "loginContext", "aresNotification", "aresDialog", "dataDicSvc", function(n, t, i, r, u, f) {
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventory-service-list.html",
        scope: {
            selectedService: "="
        },
        link: function(t, i) {
            var u = function(n) {
                    var t = [];
                    return n && n.length > 0 && _.each(n, function(n) {
                        var i = {
                            id: n.channelName,
                            name: n.channelDisplayName
                        };
                        t.push(i)
                    }), t
                },
                r = function(n) {
                    var r = u(n);
                    i.find("#channelService").kendoDropDownList({
                        dataTextField: "name",
                        dataValueField: "id",
                        dataSource: r,
                        change: function() {
                            t.selectedService = i.find("#channelService").val();
                            t.$apply()
                        }
                    });
                    t.selectedService = i.find("#channelService").val()
                },
                e = function() {
                    f.enabledChannelsDic.load().then(function(n) {
                        r(n)
                    }, function(t) {
                        n.error(t);
                        r(null)
                    })
                };
            (function() {
                e()
            })()
        }
    }
}]);
practiceModule.directive("apptInventorySettingContentView", ["$log", "$modal", "$q", "$window", "$timeout", "apptInventorySvc", "aresDialog", function() {
    return {
        restrict: "E",
        templateUrl: function(n, t) {
            return t.isDayInventory == "false" ? "/app/practice/views/appt-inventory/appt-inventory-setting-template-content-view.html" : "/app/practice/views/appt-inventory/appt-inventory-setting-content-view.html"
        },
        scope: {
            apptInventoryTemplate: "=",
            apptInventoryDaily: "="
        },
        link: function() {
            (function() {})()
        }
    }
}]);
practiceModule.directive("apptInventoyItemsSettingResetView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/appt-inventory/appt-inventoy-items-setting-reset-view.html",
        link: function(n, i) {
            (function() {
                n.amount = 1;
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 500)
            })()
        }
    }
}]);
patientModule.directive("practiceChargeCategoryEditView", ["$q", "$timeout", "constants", "aresNotification", "apptApplyCompleteUtil", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-category-edit-view.html",
        link: function(i, f) {
            var o = function() {
                    var t = f.find("#super-category-drop-down-list"),
                        n = t.kendoDropDownList({
                            dataSource: i.superCategoryList,
                            dataTextField: "itemName",
                            dataValueField: "id",
                            change: function(n) {
                                var t = i.superCategoryList[n.sender.selectedIndex];
                                i.category.itemSuperCategoryId = t.id;
                                i.category.itemSuperCategoryName = t.itemName
                            }
                        }).data("kendoDropDownList");
                    n.value(i.category.itemSuperCategoryId);
                    (u.isCategoryName(i.category.itemName) || !i.isEdit) && n.enable(!1);
                    s()
                },
                s = function() {
                    var t = [i.getOrganizationInfo(), i.getCategorySyncOptions()];
                    n.all(t).then(n => {
                        var t = n[0],
                            f, r, u;
                        n.length > 1 && (i.category.syncOptions = n[1]);
                        f = t && t.length > 0;
                        f && (i.showOrganizations = !0, i.organizations = t, u = i.category.syncOptions, u && u.length > 0 ? (r = [], t.forEach(n => {
                            var t = u.find(t => t.targeOrganizationId == n.id);
                            t && t.isExcluded || r.push(n.id)
                        })) : (r = t.map(n => n.id), i.category.syncOptions = e(r)), i.selectedOrgs = r)
                    })
                },
                h = function() {
                    if (!i.category.itemName) return r.error("小类项目名称不能为空！"), !1;
                    if (i.category.itemName = i.category.itemName.trim(), !i.checkNewItemNameUnique(i.category.itemName, i.category.id)) return r.error("小类项目名称已被使用！"), !1;
                    i.save(i.category).then(function() {
                        r.success("保存成功")
                    }, function() {
                        r.error("保存失败")
                    })
                },
                e = function(n) {
                    if (!n) return null;
                    var t = [];
                    return i.organizations.forEach(i => {
                        t.push({
                            targetOfficeId: i.id,
                            isExcluded: n.indexOf(i.id) == -1
                        })
                    }), t
                },
                c = function(n) {
                    i.category.syncOptions = e(n)
                },
                l = function() {
                    i.category.isInDeal = !i.category.isInDeal
                },
                a = function() {
                    return u.isCategoryName(i.category.itemName)
                },
                v = function() {
                    return u.isCategoryName(i.category.itemName)
                };
            (function() {
                i.isEdit = i.category.id > 0;
                i.onSave = h;
                i.onOrganizationSelected = c;
                i.onIsInDealClick = l;
                i.isDisabledEditName = a;
                i.isDisabledEditInDeal = v;
                o();
                t(function() {
                    Ares.centerModal(f.closest(".modal-dialog"));
                    f.find("#category-name-input").focus()
                }, 5)
            })()
        }
    }
}]);
patientModule.directive("practiceChargeCategoryView", ["$log", "$q", "appNav", "$compile", "$timeout", "$modal", "aresNotification", "aresDialog", "constants", "apptApplyCompleteUtil", function(n, t, i, r, u, f, e, o, s, h) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-category-view.html",
        controller: "PracticeChargeCategoryCtrl",
        scope: !0,
        link: function(n, i) {
            var l = function(n, t, i, r) {
                    var u = r ? "\" ares-hide-when-parent='ChargeItem'" : '"';
                    return '<a charge-order-id="#: id # " action="' + n + '" class="grid-command-glyphicon"                        data-toggle="tooltip" data-placement="top" data-original-title="' + t + u + '>                        <span class="glyphicon ' + i + '"><\/span>                    <\/a>'
                },
                c = null,
                p = {},
                w = null,
                b = null,
                u = {
                    element: null,
                    categoryId: null,
                    superCategoryId: null,
                    empty: function() {
                        this.element.removeClass("k-state-selected");
                        this.categoryId = null;
                        this.superCategoryId = null
                    }
                },
                k = !0,
                it = function() {
                    var t = [{
                        field: "displayOrder",
                        title: "序号",
                        width: "60px",
                        attributes: {
                            style: "text-align: center; font-size: 15px; font-weight: 400;"
                        },
                        headerAttributes: {
                            style: "text-align: center; font-size: 15px; font-weight: 400;"
                        }
                    }, {
                        field: "itemName",
                        title: "大类名称",
                        width: "300px",
                        attributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;"
                        }
                    }, {
                        field: "itemEnglishName",
                        title: "英文名称",
                        attributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;"
                        }
                    }];
                    if (n.isChargeItemEditAllowed) {
                        var i = l("super-edit", "编辑", "glyphicon-edit", !0),
                            r = l("super-delete", "删除", "glyphicon-trash", !0),
                            u = {
                                template: function(n) {
                                    return n.itemName == s.ValueAddSuperCategoryName ? i : i + r
                                },
                                title: "操作",
                                width: "120px",
                                headerAttributes: {
                                    style: "text-align: center; font-size: 15px; font-weight: 400;"
                                }
                            };
                        t.push(u)
                    }
                    return t
                },
                rt = function() {
                    if (n.chargeItemSuperCategorys) {
                        var t = it();
                        return {
                            dataSource: {
                                data: n.chargeItemSuperCategorys
                            },
                            scrollable: !1,
                            detailInit: ft,
                            sortable: !1,
                            selectable: !1,
                            model: {
                                id: "id"
                            },
                            dataBound: et,
                            columns: t
                        }
                    }
                },
                d = function() {
                    var n = rt();
                    c = i.find("#charge-category-grid").kendoGrid(n).data("kendoGrid");
                    ut()
                },
                ut = function() {
                    var i = c.tbody,
                        f = i.find(".k-hierarchy-cell");
                    f.on("click", "a.k-icon", function(n) {
                        var t = i.find(this),
                            u = t.parents("tr"),
                            r = u.next();
                        r.is(":visible") ? (u.removeClass("detail-expand"), r.hide(), v(), t.removeClass("k-minus"), t.addClass("k-plus")) : (t.removeClass("k-plus"), t.addClass("k-minus"), r.css({
                            display: "table-row"
                        }), u.addClass("detail-expand"), u.hasClass("hover-color") && !r.hasClass("hover-color") && r.addClass("hover-color"), v());
                        n.stopPropagation()
                    });
                    i.on("click", "tr", function(n) {
                        var e = i.find(n.target),
                            t, r, f;
                        if (e.hasClass("k-icon") || (t = i.find(this), t.hasClass("new-super-category-item-view") || t.hasClass("k-detail-row"))) return !1;
                        if (t.hasClass("k-state-selected")) u.element && u.empty();
                        else {
                            if (u.element && u.empty(), r = c.dataItem(t), !r) return !1;
                            f = r.id;
                            t.addClass("k-state-selected");
                            u.element = t;
                            u.superCategoryId = f
                        }
                    });
                    i.on("click", 'a[action="super-edit"]', function(r) {
                        r.stopImmediatePropagation();
                        r.stopPropagation();
                        v();
                        var f = i.find(this),
                            e = f.parents("tr").eq(0),
                            u = c.dataItem(e);
                        return n.checkSuperCategoryItemUsedChargeOrderPromise(u.id).then(function(n) {
                            if (n) return o.confirm("提示", "此收费大类已有过收费记录，修改后将影响统计报表，确定要修改此配置？");
                            var i = t.defer();
                            return i.resolve(), i.promise
                        }).then(function() {
                            nt(u).then(function() {
                                a()
                            })
                        }), !1
                    });
                    i.on("click", 'a[action="super-delete"]', function(t) {
                        t.stopImmediatePropagation();
                        t.stopPropagation();
                        var u = i.find(this),
                            f = u.parents("tr").eq(0),
                            r = c.dataItem(f);
                        return n.checkSuperCategoryItemHasCategoryItemPromise(r.id).then(function() {
                            e.error("该收费大类下有子类未删除，请清空子类后再删除收费大类！")
                        }, function() {
                            n.checkSuperCategoryItemUsedChargeOrderPromise(r.id).then(function(t) {
                                var i = t ? "此收费大类已有过收费记录，删除后将影响统计报表，确定要删除此配置？" : "确定要删除此配置？";
                                o.confirm("提示", i).then(function() {
                                    n.deleteSuperCategoryItemPromise(r.id).then(function() {
                                        e.success("删除成功！");
                                        a()
                                    }).catch(function() {
                                        e.error("删除失败")
                                    })
                                })
                            })
                        }), !1
                    });
                    r(i)(n)
                },
                ft = function(t) {
                    n.getCategoryListBySuperCategoryPromise(t.data.id).then(function(n) {
                        lt(t.detailCell, n, t.data.id)
                    })
                },
                et = function(n) {
                    var t = this,
                        i = n.sender.tbody;
                    i.find("tr.k-master-row").each(function(n, r) {
                        var u = i.find(r),
                            f = u.next();
                        t.expandRow(u);
                        u.addClass("detail-expand");
                        n === 0 && k ? k = !1 : (u.removeClass("detail-expand"), t.collapseRow(u));
                        u.hasClass("hover-color") && !f.hasClass("hover-color") && f.addClass("hover-color")
                    })
                },
                ot = function() {
                    var r = '<a charge-order-id="1 " action="super-edit" class="grid-command-glyphicon" data-toggle="tooltip" data-placement="top" data-original-title="编辑">                                            <span class="glyphicon glyphicon-edit"><\/span>                                        <\/a>',
                        o = c.tbody,
                        u = o.find(".new-super-category-item-view"),
                        n = u.find("td"),
                        t = n.eq(2),
                        i = n.eq(3),
                        f = n.eq(4),
                        e = t.attr("itemName"),
                        h = i.attr("itemEnglishName");
                    t.empty();
                    i.empty();
                    f.empty();
                    t.text(e);
                    e != s.ValueAddSuperCategoryName && (r += '<a charge-order-id="1 " action="super-delete" class="grid-command-glyphicon" data-toggle="tooltip" data-placement="top" data-original-title="删除">                                                <span class="glyphicon glyphicon-trash"><\/span>                                            <\/a>');
                    i.text(h);
                    f.append(r);
                    u.removeClass("new-super-category-item-view")
                },
                st = function() {
                    var n = kt(),
                        t = {
                            displayOrder: n + 1
                        };
                    nt(t).then(function() {
                        a()
                    })
                },
                a = function(t) {
                    n.getSuperCategoryListPromise(!0).then(function() {
                        if (n.initData(), c.wrapper.empty(), d(), u.superCategoryId != undefined && t) {
                            var i = _.findIndex(n.chargeItemSuperCategorys, function(n) {
                                    return u.superCategoryId == n.id
                                }),
                                r = c.tbody.find("tr.k-master-row");
                            u.element = r.eq(i);
                            u.element.addClass("k-state-selected")
                        }
                    })
                },
                ht = function() {
                    var t = [{
                        field: "itemName",
                        title: "小类名称",
                        headerAttributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        },
                        attributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        }
                    }, {
                        field: "itemEnglishName",
                        title: "英文名称",
                        headerAttributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        },
                        attributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        }
                    }, {
                        field: "isInDeal",
                        title: "是否成交",
                        template: function(n) {
                            return n.isInDeal ? "是" : "否"
                        },
                        headerAttributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        },
                        attributes: {
                            style: "text-align: left; font-size: 15px; font-weight: 400;padding:0 10px;"
                        }
                    }];
                    if (n.isChargeItemEditAllowed) {
                        var i = l("edit", "编辑", "glyphicon-edit", !1),
                            r = l("delete", "删除", "glyphicon-trash", !0),
                            u = {
                                template: function(n) {
                                    return h.isCategoryName(n.itemName) ? i : i + r
                                },
                                title: "操作",
                                width: "120px",
                                headerAttributes: {
                                    style: "text-align: center; font-size: 15px; font-weight: 400;"
                                }
                            };
                        t.push(u)
                    }
                    return t
                },
                ct = function(n, t) {
                    var i = ht();
                    return {
                        dataSource: n,
                        scrollable: !1,
                        sortable: !1,
                        selectable: !1,
                        dataBound: function(n) {
                            vt.call(this, n, t)
                        },
                        columns: i
                    }
                },
                lt = function(n, t, i) {
                    var r = ct(t, i);
                    p[i] = angular.element("<div class='category-list-grid'/>").appendTo(n).kendoGrid(r).data("kendoGrid");
                    at(i)
                },
                at = function(i) {
                    var s = p[i],
                        h = _.find(n.chargeItemSuperCategorys, function(n) {
                            return n.id === i
                        }),
                        f = s.tbody;
                    f.on("click", "tr", function(n) {
                        var t, r;
                        if (n.stopPropagation(), t = f.find(this), t.hasClass("add-category-btn-wrap") || t.hasClass("new-category-item-view")) return !1;
                        if (t.hasClass("k-state-selected")) u.element && u.empty();
                        else {
                            if (u.element && u.empty(), t.addClass("k-state-selected"), r = s.dataItem(t), !r) return !1;
                            u.element = t;
                            u.categoryId = r.id;
                            u.superCategoryId = i
                        }
                        return !1
                    });
                    f.on("click", 'a[action="edit"]', function(i) {
                        i.stopPropagation();
                        v();
                        ot();
                        var u = f.find(this),
                            e = u.parents("tr").eq(0),
                            r = s.dataItem(e),
                            c = r.itemName,
                            h = r.id;
                        return n.checkCategoryItemUsedChargeOrderPromise(h).then(function(n) {
                            var i = t.defer();
                            return n ? o.confirm("提示", "此收费小类已有过收费记录，修改后将影响统计报表，确定要修改此配置？").then(function() {
                                i.resolve()
                            }) : i.resolve(), i.promise
                        }).then(function() {
                            g(r).then(function() {
                                y()
                            })
                        }), !1
                    });
                    f.on("click", 'a[action="delete"]', function(t) {
                        t.stopPropagation();
                        var r = f.find(this),
                            u = r.parents("tr").eq(0),
                            i = s.dataItem(u);
                        return n.checkCategoryItemHasChargeItemPromise(i.id).then(function() {
                            e.error("该收费小类下有子项目未删除，请清空子项目后再删除收费小类！")
                        }, function() {
                            n.checkCategoryItemUsedChargeOrderPromise(i.id).then(function(t) {
                                var r = t ? "此收费小类已有过收费记录，删除后将影响统计报表，确定要删除此配置？" : "确定要删除此配置？";
                                o.confirm("提示", r).then(function() {
                                    n.deleteCategoryItemPromise(i.id).then(function() {
                                        y();
                                        e.success("删除成功！")
                                    }).catch(function() {
                                        e.error("删除失败")
                                    })
                                })
                            })
                        }), !1
                    });
                    r(f)(n)
                },
                vt = function(t, r) {
                    var u = t.sender,
                        f = u.dataItems(this),
                        e = _.find(n.chargeItemSuperCategorys, function(n) {
                            return n.id === r
                        });
                    u.tbody.children().each(function(n, t) {
                        var r, o;
                        n === f.length - 1 && (r = f[n], r.itemName === "添加小类") && (o = i.find(t), yt(o, u.tbody, e))
                    })
                },
                yt = function(n, t, i) {
                    var f;
                    n.css({
                        textAlign: "center"
                    });
                    n.addClass("add-category-btn-wrap");
                    n.attr("ares-hide-when-parent", "ChargeItem");
                    var u = n.find("td"),
                        r = u.eq(0),
                        e = u.eq(2),
                        o = u.eq(3);
                    r.attr("colspan", "3");
                    o.remove();
                    e.remove();
                    r.empty();
                    f = '<a href="javascript:void(0);" class="add-category-btn" >                        <span class="add-category-icon">+<\/span>                        <span class="add-category-text">添加小类<\/span>                        <\/a>';
                    r.append(f);
                    r.find(".add-category-btn").on("click", function() {
                        var n = dt(i.catagoryItems);
                        g({
                            itemSuperCategoryId: i.id,
                            itemSuperCategoryName: i.itemName,
                            displayOrder: n + 1
                        }).then(function() {
                            y()
                        })
                    })
                },
                g = function(t) {
                    return f.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-charge-category-edit-view><\/practice-charge-category-edit-view>",
                        controller: "PracticeChargeCategoryEditCtrl",
                        size: "md",
                        resolve: {
                            host: function() {
                                return {
                                    checkNewItemNameUnique: n.checkNewItemNameUnique,
                                    superCategoryList: n.chargeItemSuperCategorys,
                                    category: {
                                        id: t.id,
                                        itemName: t.itemName,
                                        itemEnglishName: t.itemEnglishName,
                                        isInDeal: t.isInDeal,
                                        displayOrder: t.displayOrder,
                                        itemSuperCategoryId: t.itemSuperCategoryId,
                                        itemSuperCategoryName: t.itemSuperCategoryName,
                                        syncOptions: t.syncOptions
                                    }
                                }
                            }
                        }
                    }).result
                },
                nt = function(t) {
                    return f.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-charge-super-category-edit-view><\/practice-charge-super-category-edit-view>",
                        controller: "PracticeChargeSuperCategoryEditCtrl",
                        size: "md",
                        resolve: {
                            host: function() {
                                return {
                                    superCategory: {
                                        id: t.id,
                                        itemName: t.itemName,
                                        itemEnglishName: t.itemEnglishName,
                                        displayOrder: t.displayOrder,
                                        syncOptions: t.syncOptions
                                    },
                                    checkNewItemNameUnique: function(t) {
                                        return n.checkNewItemNameUnique(t.itemName, null, t.id)
                                    }
                                }
                            }
                        }
                    }).result
                },
                v = function() {
                    w && w.remove();
                    b && b.remove()
                },
                y = function(t) {
                    n.getCategoryListPromise(!0).then(function() {
                        n.initData();
                        n.chargeItemSuperCategorys.forEach(function(i) {
                            n.getCategoryListBySuperCategoryPromise(i.id).then(function(n) {
                                var r = p[i.id],
                                    o = new kendo.data.DataSource({
                                        data: n
                                    }),
                                    f, e;
                                r.setDataSource(o);
                                u.categoryId != undefined && t && u.superCategoryId == i.id && (f = _.findIndex(n, function(n) {
                                    return u.categoryId == n.id
                                }), e = r.tbody.children(), u.element = e.eq(f), u.element.addClass("k-state-selected"))
                            })
                        })
                    })
                },
                pt = function() {
                    tt(function(n, t) {
                        if (n === 0) return !1;
                        var i = t[n - 1];
                        return t[n - 1] = t[n], t[n] = i, !0
                    }, function(t) {
                        if (t === 0) return !1;
                        var i = n.chargeItemSuperCategorys[t - 1];
                        return n.chargeItemSuperCategorys[t - 1] = n.chargeItemSuperCategorys[t], n.chargeItemSuperCategorys[t] = i, !0
                    })
                },
                wt = function() {
                    tt(function(n, t) {
                        if (n === t.length - 1) return !1;
                        var i = t[n + 1];
                        return t[n + 1] = t[n], t[n] = i, !0
                    }, function(t, i) {
                        if (t === i - 1) return !1;
                        var r = n.chargeItemSuperCategorys[t + 1];
                        return n.chargeItemSuperCategorys[t + 1] = n.chargeItemSuperCategorys[t], n.chargeItemSuperCategorys[t] = r, !0
                    })
                },
                tt = function(t, i) {
                    var r, f, s, o;
                    if (u.superCategoryId)
                        if (r = u.superCategoryId, f = u.categoryId, f) {
                            var h = _.find(n.chargeItemSuperCategorys, function(n) {
                                    return n.id === r
                                }),
                                e = h.catagoryItems,
                                o = _.findIndex(e, function(n) {
                                    return f === n.id
                                });
                            if (!t(o, e)) return;
                            s = e.filter(function(n) {
                                return n.id !== 0
                            });
                            s.forEach(function(n, t) {
                                n.displayOrder = t + 1
                            });
                            n.updateCategoryItemListPromise(s).then(function() {
                                u.element.removeClass("k-state-selected");
                                y(!0)
                            })
                        } else {
                            if (o = _.findIndex(n.chargeItemSuperCategorys, function(n) {
                                    return n.id === r
                                }), !i(o, n.chargeItemSuperCategorys.length)) return;
                            n.chargeItemSuperCategorys.forEach(function(n, t) {
                                n.displayOrder = t + 1
                            });
                            n.updateSuperCategoryItemListPromise(n.chargeItemSuperCategorys).then(function() {
                                u.element.removeClass("k-state-selected");
                                a(!0)
                            })
                        }
                },
                bt = function() {
                    d()
                },
                kt = function() {
                    var t = n.chargeItemSuperCategorys.map(function(n) {
                        return n.displayOrder
                    }).filter(function(n) {
                        return n == 0 || n
                    });
                    return t.length > 0 ? Math.max.apply(null, t) : 0
                },
                dt = function(n) {
                    var t = n.map(function(n) {
                        return n.displayOrder
                    }).filter(function(n) {
                        return n == 0 || n
                    });
                    return t.length > 0 ? Math.max.apply(null, t) : 0
                };
            (function() {
                n.initView = bt;
                n.addSuperCategoryItem = st;
                n.moveItemUp = pt;
                n.moveItemDown = wt
            })()
        }
    }
}]);
patientModule.directive("practiceChargeDeductionItemsView", ["$log", "$timeout", "$modal", "$window", "dataDicSvc", "membershipSvc", "printUtil", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-deduction-items-view.html",
        link: function(n, i) {
            var f = Ares.kendoGridUtil(r, n),
                u = function() {
                    i.find("#chargeItemList").kendoGrid({
                        dataSource: {
                            transport: {
                                read: function(t) {
                                    n.pageIndex = t.data.page || 1;
                                    n.pageSize = t.data.pageSize || 15;
                                    t.data.sort && t.data.sort.length > 0 ? (n.sortField = t.data.sort[0].field, n.sortDirection = t.data.sort[0].dir == "asc" ? 0 : 1) : (n.sortField = null, n.sortDirection = null);
                                    t.data.pageSize ? n.onPageChanged().then(function(n) {
                                        t.success(n)
                                    }) : t.success({
                                        totalCount: 0,
                                        items: []
                                    })
                                }
                            },
                            schema: {
                                data: "items",
                                total: "totalCount"
                            },
                            pageSize: 15,
                            serverPaging: !0,
                            serverSorting: !0,
                            serverFiltering: !0
                        },
                        pageable: !0,
                        height: 400,
                        scrollable: !0,
                        sortable: !0,
                        selectable: "single",
                        columns: [{
                            field: "index",
                            title: "序号",
                            width: "30px",
                            sortable: !1,
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight:bold"
                            }
                        }, {
                            field: "itemSuperCategoryName",
                            title: "所属大类",
                            width: "130px",
                            sortable: !1,
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight:bold"
                            }
                        }, {
                            field: "itemCatagoryName",
                            title: "所属小类",
                            width: "130px",
                            sortable: !1,
                            headerAttributes: {
                                style: "text-align: center; font-size: 14px; font-weight:bold"
                            }
                        }, {
                            field: "itemName",
                            title: "项目名称 ",
                            width: "130px"
                        }]
                    }).data("kendoGrid")
                };
            (function() {
                u()
            })();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceChargeDeductionPlanView", ["$log", "$timeout", "$window", "aresNotification", "deductionSvc", "aresDialog", "$modal", function(n, t, i, r, u, f, e) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/charge/practice-charge-deduction-plan-view.html",
        controller: "PracticeChargeDeductionPlanCtrl",
        link: function(n, r) {
            var u = function() {
                    n.selectedDeductionPlan = {
                        planName: "",
                        steps: [{
                            stepName: "",
                            stepIndex: 1,
                            stepRatio: 100,
                            stepManHours: 1
                        }]
                    };
                    n.isEdit = !0
                },
                o = function(t) {
                    n.selectedDeductionPlan = angular.copy(t);
                    n.isEdit = !1
                },
                s = function(i) {
                    i && (n.selectedDeductionPlan = angular.copy(i));
                    n.srcEditDeductionPlan = angular.copy(n.selectedDeductionPlan);
                    t(function() {
                        n.isEdit = !0
                    })
                },
                h = function(t) {
                    return f.confirm("提示", "确定要删除此划扣方案配置").then(function() {
                        n.deletePlan(t.id)
                    }), !1
                },
                c = function(t) {
                    n.selectedDeductionPlan = angular.copy(t);
                    var i = e.open({
                        animation: !0,
                        controller: "PracticeChargeDeductionItemsCtrl",
                        backdrop: "static",
                        template: "<practice-charge-deduction-items-view><\/practice-charge-deduction-items-view>",
                        size: "lg",
                        resolve: {
                            host: function() {
                                return {
                                    deductionPlanId: n.selectedDeductionPlan.id
                                }
                            }
                        }
                    })
                },
                l = function() {
                    n.save()
                },
                a = function() {
                    n.isEdit = !1;
                    n.selectedDeductionPlan.id ? (n.selectedDeductionPlan = n.srcEditDeductionPlan, n.srcEditDeductionPlan = null) : n.selectedDeductionPlan = null
                },
                v = function() {
                    var t = n.selectedDeductionPlan.steps.length;
                    n.selectedDeductionPlan.steps.push({
                        stepName: "",
                        stepIndex: t + 1,
                        stepRatio: 100,
                        stepManHours: 1
                    })
                },
                y = function(t) {
                    n.selectedDeductionPlan.steps.splice(t, 1);
                    n.selectedDeductionPlan.steps.forEach(function(n, t) {
                        n.stepIndex = t + 1
                    })
                },
                p = function() {
                    var n = angular.element(i.document).height() - 112 - (window.Ares3 ? 25 : 0),
                        u = r.find(".deduction-plan-list-wrap"),
                        f = u.find(".deduction-plan-list");
                    f.height(n - 40);
                    u.height(n);
                    t(function() {
                        var n = r.find(".deduction-icon");
                        n.tooltip()
                    }, 800)
                },
                w = function() {
                    t(function() {
                        $.fn.mCustomScrollbar && r.find(".deduction-plan-list").mCustomScrollbar({
                            scrollButtons: {
                                enable: !1
                            },
                            autoHideScrollbar: !0,
                            scrollInertia: 150,
                            advanced: {
                                updateOnContentResize: !0
                            }
                        })
                    }, 100)
                },
                b = function(n) {
                    t(function() {
                        var t = r.find(".deduction-plan-list"),
                            i;
                        t.mCustomScrollbar("update");
                        n ? t.mCustomScrollbar("scrollTo", "top") : t.mCustomScrollbar("scrollTo", "bottom");
                        i = r.find(".deduction-icon");
                        i.tooltip()
                    }, 100)
                },
                k = function(n) {
                    n.isRepeatable ? (n.isAllowSkip = !1, n.isAutoExecute = !1) : n.defaultRepeatCount = null
                },
                d = function(n) {
                    n.isAllowSkip && (n.isRepeatable = !1, n.defaultRepeatCount = null)
                },
                g = function(n) {
                    n.isAutoExecute && (n.isRepeatable = !1, n.defaultRepeatCount = null)
                },
                nt = function(t) {
                    if (!t.followupRuleId) return "";
                    var i = _.find(n.followupRuleLites, function(n) {
                        return n.id == t.followupRuleId
                    });
                    return i ? i.name : ""
                };
            (function() {
                n.createDedutionPlanspan = u;
                n.selectDeductionPlan = o;
                n.editDeductionPlan = s;
                n.deleteDeductionPlan = h;
                n.queryDeductionPlan = c;
                n.saveDeductionPlan = l;
                n.cleanDeductionPlan = a;
                n.addDeductionPlanStep = v;
                n.removeDedutionPlanStep = y;
                n.getFollowupRuleTitle = nt;
                n.initListView = w;
                n.updateListView = b;
                n.onIsAutoExecuteClick = g;
                n.onIsRepeatableClick = k;
                n.onIsAllowSkipClick = d;
                p()
            })()
        }
    }
}]);
practiceModule.directive("practiceChargeHomeView", ["$log", "$timeout", "$filter", "$window", "appNav", "enums", "chargeSvc", "loginContext", "permissionProvider", "systemConfigUtil", "dataDicSvc", function(n, t, i, r, u, f, e, o, s, h, c) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/charge/practice-charge-home-view.html",
        link: function(n) {
            var t = function() {
                    e.getThirdPartyPayConfig().success(function(t) {
                        const e = t && t.length > 0;
                        var u = [new Ares.TabItem("setting.charge.category", "收费类别配置", "glyphicon glyphicon-cog", "setting.chargeCategory"), new Ares.TabItem("setting.charge.itemBrowser", "收费项目配置", "glyphicon glyphicon-cog", "setting.chargeItem"), new Ares.TabItem("setting.charge.package", "收费项目套餐配置", "glyphicon glyphicon-cog", "setting.chargePackage"), new Ares.TabItem("setting.charge.chargeType", "费用类型配置", "glyphicon glyphicon-cog", "setting.chargeType"), new Ares.TabItem("setting.charge.paymentType", "支付方式配置", "glyphicon glyphicon-cog", "setting.paymentType"), new Ares.TabItem("setting.charge.deductionPlan", "划扣方案配置", "glyphicon glyphicon-cog", "setting.chargedeductionPlan", null, i), new Ares.TabItem("setting.charge.itemFreeField", "自由项配置", "glyphicon glyphicon-cog", "setting.chargeitemFreefield", null, f), new Ares.TabItem("setting.charge.lcPayGateway", "领健在线收银配置", "glyphicon glyphicon-cog", "setting.chargeType", null, r), ];
                        e && u.push(new Ares.TabItem("setting.charge.thirdPartyDevices", "收银设备管理", "glyphicon glyphicon-cog", ""));
                        n.states = u
                    })
                },
                i = function() {
                    return n.allowChargeDeduction
                },
                r = function() {
                    return n.isLcPayGatewayVisible
                },
                f = function() {
                    return n.hasFreeFields
                },
                o = function(n) {
                    u.goToState(n)
                },
                s = function() {
                    c.officeSettingDic.load().then(function(t) {
                        n.allowChargeDeduction = t.isDeductionChargeEnabled;
                        n.isLcPayGatewayVisible = t.isLcPayGatewayVisible;
                        n.allowChargeDeduction || n.$root.currentState != "setting.charge.deductionPlan" || (n.$root.currentState = "setting.charge.category", o(n.$root.currentState))
                    });
                    c.chargeItemFreeFieldDic.load().then(function(t) {
                        n.hasFreeFields = t && t.length ? !0 : !1
                    })
                };
            (function() {
                t();
                s()
            })()
        }
    }
}]);
var charge;
(function(n) {
    var t = function() {
        function n(n, t, i, r, u) {
            var f = this;
            this.$log = n;
            this.$q = t;
            this.$timeout = i;
            this.chargeSvc = r;
            this.loginContext = u;
            this.replace = !0;
            this.restrict = "E";
            this.templateUrl = "/app/practice/views/charge/practice-charge-item-favorite-edit-view.html";
            this.requestLock = !1;
            this.link = function(n, t) {
                var i = function() {};
                (function() {
                    i();
                    f.$timeout(function() {
                        Ares.centerModal(t.closest(".modal-dialog"))
                    }, 5)
                })()
            }
        }
        return n.$inject = ["$log", "$q", "$timeout", "chargeSvc", "loginContext"], n
    }();
    n.PracticeChargeItemFavoriteEditView = t;
    practiceModule.directive("practiceChargeItemFavoriteEditView", Ares.tsDirective(t))
})(charge || (charge = {}));
var charge;
(function(n) {
    var t = function() {
        function n(n, t, i) {
            this.$log = n;
            this.$q = t;
            this.$timeout = i;
            this.replace = !0;
            this.restrict = "E";
            this.templateUrl = "/app/practice/views/charge/practice-charge-item-favorite-view.html";
            this.controller = "PracticeChargeItemFavoriteCtrl";
            this.requestLock = !1;
            this.link = function() {
                var n = function() {};
                (function() {
                    n()
                })()
            }
        }
        return n.$inject = ["$log", "$q", "$timeout"], n
    }();
    n.PracticeChargeItemFavoriteView = t;
    practiceModule.directive("practiceChargeItemFavoriteView", Ares.tsDirective(t))
})(charge || (charge = {}));
practiceModule.directive("practiceChargeItemFreeFieldView", ["$log", "$timeout", "$q", "officeUtil", "$window", "aresNotification", function(n, t, i, r, u, f) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-item-free-field-view.html",
        controller: "PracticeChargeItemFreeFieldCtrl",
        link: function(n, i) {
            var r = function() {
                    var t = angular.element(u).height();
                    i.find(".data-panel-body").each(function() {
                        var t = angular.element(this),
                            i = n.chargeItemAboutEnabled ? t.siblings(".data-panel-footer").height() : 0;
                        t.css("max-height", 490 - i + "px");
                        t.data("mCustomScrollbarIndex") ? t.mCustomScrollbar("update") : t.mCustomScrollbar({
                            scrollButtons: {
                                enable: !1
                            },
                            scrollInertia: 150,
                            advanced: {
                                updateOnContentResize: !0
                            }
                        })
                    })
                },
                s = function() {
                    i.on("blur", "input.list-input-group-input", function() {
                        var n = $(this);
                        n.val().trim() ? n.siblings(".list-input-btn").click() : n.parent(".list-input-group").removeClass("focused").addClass("warning")
                    }).on("keyup", ".list-input-group-input", function(n) {
                        var t = $(this);
                        n.keyCode === 13 && (t.val().trim() ? t.siblings(".list-input-btn").click() : t.parent(".list-input-group").removeClass("focused").addClass("warning"))
                    })
                },
                h = function() {
                    i.find('[data-toggle="tooltip"]').tooltip()
                },
                c = function(n, t) {
                    var i = angular.element(t.target);
                    i.siblings(".list-input-group").removeClass("warning").addClass("focused").show().find("input").focus();
                    i.addClass("disabled");
                    r()
                },
                e = !1,
                l = function(t, i) {
                    if (!e) {
                        e = !0;
                        var u = n.newItemName[t];
                        n.addItem(t, u).then(function() {
                            n.newItemName[t] = null;
                            f.success("保存成功");
                            var u = angular.element(i.target).closest(".list-input-group").removeClass("warning").removeClass("focused").hide();
                            u.siblings(".list-new-btn").removeClass("disabled");
                            r()
                        }).catch(function(n) {
                            n.name === "SystemItemNameNotUniqueException" ? f.error("已经有其他项目使用此名称，请更换新名称！") : n.msg && f.error(n.msg)
                        }).finally(function() {
                            e = !1
                        })
                    }
                },
                a = function(t) {
                    var r = n.selectedItem[t],
                        i = _.findIndex(n.freeFieldDicts[t], function(n) {
                            return n.id === r.id
                        });
                    n.movableStatus[t] = {
                        up: i !== 0,
                        down: i !== n.freeFieldDicts[t].length - 1
                    }
                },
                v = function(t, i) {
                    n.selectedItem[t] = i;
                    a(t)
                },
                o, y = function(i, r) {
                    o && t.cancel(o);
                    var e = n.selectedItem[i],
                        u = _.findIndex(n.freeFieldDicts[i], function(n) {
                            return n.id === e.id
                        }),
                        f = r === "up" ? u - 1 : u + 1;
                    n.movableStatus[i] = {
                        up: f !== 0,
                        down: f !== n.freeFieldDicts[i].length - 1
                    };
                    n.freeFieldDicts[i].splice(u, 1);
                    n.freeFieldDicts[i].splice(f, 0, e);
                    _.each(n.freeFieldDicts[i], function(n, t) {
                        n.displayOrder = t + 1
                    });
                    o = t(function() {
                        n.updateList(i)
                    }, 2e3)
                },
                p = function() {
                    n.initSystemItems().then(function() {
                        s();
                        t(function() {
                            r();
                            h()
                        })
                    })
                };
            (function() {
                n.initView = r;
                n.onNewBtnClick = c;
                n.onSaveNewItem = l;
                n.onListItemSelected = v;
                n.move = y;
                n.movableStatus = {};
                p()
            })()
        }
    }
}]);
var charge;
(function(n) {
    var t = function() {
        function n(n, t, i, r, u) {
            var f = this;
            this.$window = n;
            this.commonSvc = t;
            this.$q = i;
            this.systemConfigSvc = r;
            this.loginContext = u;
            this.replace = !0;
            this.restrict = "E";
            this.templateUrl = "/app/practice/views/charge/practice-charge-lc-pay-gateway-view.html";
            this.requestLock = !1;
            this.link = function(n, t) {
                var i = function() {
                        t.find("#charge-lc-pay-gateway-settting").height(angular.element(f.$window).height() - 110);
                        r()
                    },
                    r = function() {
                        f.systemConfigSvc.getOpenPlatformPaymentUrl().then(function(n) {
                            var i = document.createElement("iframe");
                            i.src = n;
                            i.style.width = "100%";
                            i.style.height = "100%";
                            t.find("#charge-lc-pay-gateway-settting")[0].appendChild(i)
                        })
                    };
                (function() {
                    i()
                })()
            }
        }
        return n.$inject = ["$window", "commonSvc", "$q", "systemConfigSvc", "loginContext"], n
    }();
    n.PracticeChargeLcPayGatewayView = t;
    practiceModule.directive("practiceChargeLcPayGatewayView", Ares.tsDirective(t))
})(charge || (charge = {}));
practiceModule.directive("practiceChargePackageCategoryEditView", ["$log", "$timeout", "aresDialog", "practiceSvc", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-package-category-edit-view.html",
        link: function(n, i) {
            (function() {})();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceChargePackageCategoryMoveView", ["$log", "$timeout", "aresDialog", "loginContext", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-package-category-move-view.html",
        link: function(n) {
            var t = null,
                u = function(i) {
                    n.selectedNode = i;
                    n.categoryId = i.id;
                    n.clickedName = i.itemName;
                    i && (i.name === "收费套餐" || i.name === "收费套餐") && (t = r.userId)
                },
                f = function() {
                    var r = {
                        id: n.chargePackage.id,
                        categoryId: n.categoryId ? n.categoryId : 0,
                        userId: t
                    };
                    if (!(n.categoryId === 0 || n.categoryId)) {
                        i.info("提示", "请选择目录！");
                        return
                    }
                    n.movePackage(r)
                };
            (function() {
                n.getContent = u;
                n.sureMovePackage = f
            })()
        }
    }
}]);
practiceModule.directive("practiceChargePackageEditView", ["$log", "$timeout", "aresDialog", "practiceSvc", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-package-edit-view.html",
        controller: "PracticeChargePackageEditCtrl",
        scope: {
            chargePackage: "=",
            displayOrder: "=",
            chargePackages: "=",
            isDialog: "=",
            close: "=?",
            moveMethod: "=?"
        },
        link: function(n, i) {
            (function() {})();
            t(function() {
                Ares.centerModal(i.closest(".modal-dialog"))
            }, 5)
        }
    }
}]);
practiceModule.directive("practiceChargePackageView", ["$log", "$compile", "$timeout", "$window", function() {
    "use strict";
    return {
        templateUrl: "/app/practice/views/charge/practice-charge-package-view.html",
        controller: "PracticeChargePackageCtrl",
        link: function() {
            (function() {})()
        }
    }
}]);
patientModule.directive("practiceChargeSuperCategoryEditView", ["$q", "$timeout", "aresNotification", function(n, t, i) {
    "use strict";
    return {
        restrict: "E",
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-charge-super-category-edit-view.html",
        link: function(r, u) {
            var f = function() {
                    if (!r.superCategory.itemName) {
                        i.error("大类项目名称不能为空！");
                        return
                    }
                    if (r.superCategory.itemName = r.superCategory.itemName.trim(), !r.checkNewItemNameUnique(r.superCategory)) {
                        i.error("大类项目名称已被使用！");
                        return
                    }
                    r.save(r.superCategory).then(function() {
                        i.success("保存成功")
                    }, function() {
                        i.error("保存失败")
                    })
                },
                e = function() {
                    var t = [r.getOrganizationInfo(), r.getSuperCategorySyncOptions()];
                    n.all(t).then(function(n) {
                        var t = n[0],
                            f, i, u;
                        n.length > 1 && (r.superCategory.syncOptions = n[1]);
                        f = t && t.length > 0;
                        f && (r.showOrganizations = !0, r.organizations = t, u = r.superCategory.syncOptions, u && u.length > 0 ? (i = [], t.forEach(n => {
                            var t = u.find(t => t.targeOrganizationId == n.id);
                            t && t.isExcluded || i.push(n.id)
                        })) : i = t.map(n => n.id), r.selectedOrgs = i)
                    })
                },
                o = function(n) {
                    if (!n) return null;
                    var t = [];
                    return r.organizations.forEach(i => {
                        t.push({
                            targetOfficeId: i.id,
                            isExcluded: n.indexOf(i.id) == -1
                        })
                    }), t
                },
                s = function(n) {
                    r.superCategory.syncOptions = o(n)
                };
            (function() {
                r.isEdit = r.superCategory.id > 0;
                r.onSave = f;
                r.onOrganizationSelected = s;
                e();
                t(function() {
                    Ares.centerModal(u.closest(".modal-dialog"))
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceChargeitemBrowserView", ["$log", "$compile", "$timeout", "$window", "$modal", "constants", "apptApplyCompleteUtil", function(n, t, i, r, u, f, e) {
    "use strict";
    var s = !1,
        h = function() {
            return '<input type="checkbox" class="k-select-checkbox" ares-hide-when-parent="ChargeItem"/>'
        },
        c = function() {
            return '<input type="checkbox" class="k-all-select-checkbox" ares-hide-when-parent="ChargeItem"/>'
        },
        o = function(n, t) {
            var r = n.find(".k-select-checkbox:enabled"),
                i = t.find(".k-all-select-checkbox"),
                u = r.not(":checked");
            r.length > 0 ? (u.length > 0 ? i.removeAttr("checked") : i.prop("checked", "checked"), i.removeAttr("disabled")) : (i.removeAttr("checked"), i.prop("disabled", "disabled"))
        },
        l = function(n) {
            var i = '<a charge-order-id="' + n.id + '" action="edit" class="grid-command-glyphicon"                        data-toggle="tooltip" data-placement="top" data-original-title="编辑">                        <span class="glyphicon glyphicon-edit"><\/span>                    <\/a>',
                t = "";
            if (s && !e.isCategoryName(n.itemCatagoryName)) {
                var r = n.isDisabled ? "enable" : "disable",
                    u = n.isDisabled ? "glyphicon-ok-circle" : "glyphicon-ban-circle",
                    f = n.isDisabled ? "启用" : "禁用";
                t = '<a charge-order-id="' + n.id + '" action = "' + r + '" class="enable-stauts grid-command-glyphicon "                        data-toggle="tooltip" data-placement="top" data-original-title="' + f + "\" ares-hide-when-parent='ChargeItem'>                        <span class=\"glyphicon " + u + '"><\/span>                    <\/a>'
            }
            return i + t
        },
        a = function(n) {
            var t = kendo.toString(n.actualPrice, "n2");
            return n.payTypeStr && (t += " ( " + n.payTypeStr + " ) "), t
        };
    return {
        templateUrl: "json/index/app/practice/views/charge/practice-chargeitem-browser-view.html",
        controller: "PracticeChargeItemBrowserCtrl",
        link: function(r, f) {
            var v = null,
                a = null,
                w = null,
                b, g = function(n) {
                    var t = {
                            style: "text-align: center; font-size: 14px; font-weight: bolder; white-space: normal;"
                        },
                        i = [];
                    return !n && r.isChargeItemEditAllowed && i.push({
                        headerTemplate: c,
                        template: h,
                        width: "40px",
                        headerAttributes: t
                    }), i = i.concat([{
                        field: "index",
                        title: "编号",
                        width: "50px",
                        headerAttributes: t
                    }, {
                        field: "itemSuperCategoryName",
                        title: "大类",
                        width: "100px",
                        headerAttributes: t
                    }, {
                        field: "itemCatagoryName",
                        title: "小类",
                        width: "100px",
                        headerAttributes: t
                    }, {
                        field: "itemName",
                        title: "名称",
                        width: "160px",
                        headerAttributes: t
                    }, {
                        field: "procedureCode",
                        title: "项目编码",
                        width: "120px",
                        headerAttributes: t
                    }, {
                        field: "unit",
                        title: "单位",
                        width: "50px",
                        headerAttributes: t
                    }, {
                        field: "price",
                        title: "价格",
                        width: "80px",
                        format: "{0:n}",
                        headerAttributes: t
                    }, {
                        field: "itemSubCategory",
                        title: "费用类型",
                        width: "80px",
                        headerAttributes: t
                    }, {
                        field: "allowDiscount",
                        title: "单项打折",
                        width: "40px",
                        headerAttributes: t,
                        template: function(n) {
                            return p(n.allowDiscount)
                        },
                        attributes: {
                            style: "font-size:13px;"
                        }
                    }, {
                        field: "allowOrderDiscount",
                        title: "整单打折",
                        width: "40px",
                        headerAttributes: t,
                        template: function(n) {
                            return p(n.allowOrderDiscount)
                        },
                        attributes: {
                            style: "font-size:13px;"
                        }
                    }, {
                        field: "isInDeal",
                        title: "是否成交",
                        width: "40px",
                        headerAttributes: t,
                        template: function(n) {
                            return n.isInDeal ? "是" : "否"
                        }
                    }, {
                        field: "isDisabled",
                        title: "是否启用",
                        width: "40px",
                        headerAttributes: t,
                        template: function(n) {
                            return n.isDisabled ? "否" : "是"
                        }
                    }, ]), i.push({
                        template: l,
                        title: "操作",
                        width: "80px",
                        headerAttributes: t
                    }), i
                },
                p = function(n) {
                    return n || n == null ? "允许" : "不允许"
                },
                ft = function() {
                    var n = angular.element(window).height();
                    v = f.find("#current-catagory-charge-items-table").kendoGrid({
                        dataSource: {
                            data: r.currentCategoryChargeItems
                        },
                        columns: g(!1),
                        height: n - 202 - (window.Ares3 ? 20 : 0),
                        dataBound: et
                    }).data("kendoGrid");
                    ot()
                },
                et = function(n) {
                    var i = n.sender.tbody,
                        u = n.sender.thead,
                        e = this;
                    i.children().each(function(t, i) {
                        var u = f.find(i),
                            o = n.sender.dataItem(u),
                            s = _.find(r.selectedChargeItems, function(n) {
                                return n.id == o.id
                            }),
                            e;
                        s && (e = u.find(".k-select-checkbox:enabled"), e.prop("checked", "checked"), u.addClass("k-state-selected"))
                    });
                    o(i, u);
                    t(i)(r)
                },
                ot = function() {
                    var n = v,
                        u = n.tbody,
                        e = n.thead,
                        s = e.find(".k-all-select-checkbox");
                    u.on("change", ".k-select-checkbox:enabled", function() {
                        var r = n,
                            f = u.find(this),
                            t = f.closest("tr"),
                            e = n.dataItem(t);
                        f.is(":checked") ? i(function() {
                            t.addClass("k-state-selected");
                            nt(e.id)
                        }) : i(function() {
                            t.removeClass("k-state-selected");
                            y(e.id)
                        });
                        o(r.tbody, r.thead)
                    });
                    s.on("change", function() {
                        var t = n,
                            r = t.tbody.children(),
                            u = t.tbody.find(".k-select-checkbox:enabled"),
                            f = t.thead.find(".k-all-select-checkbox"),
                            e = f.is(":checked");
                        e ? (u.prop("checked", "checked"), r.addClass("k-state-selected"), i(function() {
                            nt(null)
                        })) : (u.removeAttr("checked"), r.removeClass("k-state-selected"), i(function() {
                            y(null)
                        }))
                    });
                    u.on("click", 'a[action="edit"]', function() {
                        var t = n,
                            i = t.dataItem(f.find(this).parents("tr"));
                        k(i)
                    });
                    u.on("click", ".enable-stauts", function() {
                        var i = n,
                            u = i.dataItem(f.find(this).parents("tr")),
                            t = _.find(r.srcChargeItems, function(n) {
                                return n.id == u.id
                            });
                        t.isDisabled = !t.isDisabled;
                        r.udpateChargeItem(t)
                    });
                    t(e)(r);
                    t(u)(r)
                },
                st = function() {
                    var n = a,
                        i = n.tbody,
                        u = n.thead;
                    i.on("click", 'a[action="edit"]', function() {
                        var t = n,
                            i = t.dataItem(f.find(this).parents("tr"));
                        k(i)
                    });
                    i.on("click", ".enable-stauts", function() {
                        var i = n,
                            u = i.dataItem(f.find(this).parents("tr")),
                            t = _.find(r.allChargeItems, function(n) {
                                return n.id == u.id
                            });
                        t.isDisabled = !t.isDisabled;
                        r.udpateChargeItem(t)
                    });
                    t(u)(r);
                    t(i)(r)
                },
                ht = function() {
                    var n = v;
                    n.setDataSource(new kendo.data.DataSource({
                        data: r.currentCategoryChargeItems
                    }));
                    ut();
                    n.refresh();
                    o(n.tbody, n.thead)
                },
                ct = function() {
                    r.upChargeItems(r.selectedChargeItems).then(function() {
                        var n = r.getSortFirstChargeItem(r.selectedChargeItems);
                        tt(n.displayOrder)
                    })
                },
                lt = function() {
                    r.downChargeItems(r.selectedChargeItems).then(function() {
                        var n = r.getSortLastChargeItem(r.selectedChargeItems);
                        tt(n.displayOrder)
                    })
                },
                at = function() {
                    wt(null)
                },
                vt = function() {
                    rt(v._data);
                    v.saveAsExcel()
                },
                nt = function(n) {
                    if (n) {
                        var t = _.find(r.currentCategoryChargeItems, function(t) {
                            return t.id == n
                        });
                        r.selectedChargeItems.push(t)
                    } else r.selectedChargeItems = r.currentCategoryChargeItems
                },
                y = function(n) {
                    if (n) {
                        var t = _.findIndex(r.selectedChargeItems, function(t) {
                            return t.id == n
                        });
                        r.selectedChargeItems.splice(t, 1)
                    } else r.selectedChargeItems = []
                },
                tt = function(n) {
                    var t = v.tbody.children().eq(n),
                        i = t.find(".k-select-checkbox");
                    i.focus()
                },
                it = function() {
                    var t, n, i;
                    a ? yt() : (t = angular.element(window).height(), n = t - 202 - (window.Ares3 ? 30 : 0), a = f.find("#all-charge-items-table").kendoGrid({
                        dataSource: {
                            data: r.allChargeItems
                        },
                        columns: g(!0),
                        height: n
                    }).data("kendoGrid"), i = a.wrapper.find(".k-grid-header").height(), a.wrapper.find(".k-grid-content").height(n - i), st())
                },
                yt = function() {
                    a.setDataSource(new kendo.data.DataSource({
                        data: r.allChargeItems
                    }));
                    a.refresh()
                },
                pt = function() {
                    rt(a._data);
                    a.saveAsExcel()
                },
                rt = function(n) {
                    n.forEach(function(n) {
                        n.allowDiscount = p(n.allowDiscount);
                        n.allowOrderDiscount = p(n.allowOrderDiscount);
                        n.isDisabled = n.isDisabled ? "否" : "是";
                        n.isInDeal = n.isInDeal ? "是" : "否"
                    })
                },
                k = function(n) {
                    var t, i, f, e, o;
                    n ? (t = n.itemCatagoryId, i = n.id) : t = r.currentCategoryItem.id;
                    f = !1;
                    n && r.isYibaoGatewayEnabled && r.gatewatYibaoItems && r.gatewatYibaoItems.length > 0 && (f = _.any(r.gatewatYibaoItems, function(t) {
                        return parseInt(t.hisObjectId) == n.id
                    }));
                    e = r.srcChargeItems.filter(function(n) {
                        return n.itemCatagoryId == t
                    }).length;
                    o = u.open({
                        animation: !0,
                        backdrop: "static",
                        template: "<practice-chargeitem-edit-view><\/practice-chargeitem-edit-view>",
                        controller: "PracticeChargeItemEditCtrl",
                        windowClass: "charge-item-edit",
                        size: "md",
                        resolve: {
                            host: function() {
                                return {
                                    chargeitemId: i,
                                    catagoryId: t,
                                    chargedisplayOrder: e,
                                    categoryItems: angular.copy(r.srcCatagoryItems),
                                    superCategoryItems: angular.copy(r.srcSuperCategoryItems),
                                    chargePackages: angular.copy(r.chargePackages),
                                    followupRuleLites: angular.copy(r.followupRuleLites),
                                    isYibaoGatewayEnabled: r.isYibaoGatewayEnabled,
                                    isGatewayYibaoItem: f,
                                    isYibaoItemPriceUpdatable: r.isYibaoItemPriceUpdatable
                                }
                            }
                        }
                    });
                    o.result.then(function(n) {
                        if (y(null), i && n.itemCatagoryId != t) {
                            var u = r.currentCategoryChargeItems.filter(function(t) {
                                return t.id != n.id
                            });
                            r.setChargeItemsSortOrderPromise(u).then(function() {
                                r.updateChargeItems(u)
                            })
                        } else r.initChargeItems(!1).then(function() {
                            return r.setCurrentCategoryChargeItemsPromise()
                        }).then(function() {
                            r.refreshCurrentCategoryChargeItemsGridData()
                        })
                    })
                },
                wt = function() {
                    var n = r.srcCatagoryItems.filter(function(n) {
                            return !e.isCategoryName(n.itemName)
                        }),
                        t = u.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<practice-chargeitem-category-edit-view><\/practice-chargeitem-category-edit-view>",
                            controller: "PracticeChargeItemCategoryEditCtrl",
                            windowClass: "charge-item-category-dialog",
                            resolve: {
                                host: function() {
                                    return {
                                        oldCategoryItem: angular.copy(r.currentCategoryItem),
                                        selectedChargeItems: angular.copy(r.selectedChargeItems),
                                        canSelectCategoryItems: n,
                                        srcChargeItems: r.srcChargeItems,
                                        setCategoryItemSortMethod: r.setChargeItemsSortOrderPromise
                                    }
                                }
                            }
                        });
                    t.result.then(function(n) {
                        var t = r.currentCategoryChargeItems.filter(function(t) {
                            return n.every(function(n) {
                                return n.id != t.id
                            })
                        });
                        y(null);
                        r.setChargeItemsSortOrderPromise(t).then(function() {
                            r.updateChargeItems(t.concat(n))
                        })
                    })
                },
                bt = function() {
                    w = f.find("#super-category-drop-down-list").kendoDropDownList({
                        dataSource: r.srcSuperCategoryItems,
                        dataTextField: "itemName",
                        dataValueField: "id",
                        change: function(n) {
                            var t = n.sender.value();
                            r.setCurrentSelectCategoryTreeData(t)
                        }
                    }).data("kendoDropDownList");
                    var n = f.find("#select-super-category-tree"),
                        t = angular.element(window).height();
                    n.height(t - 240 - (window.Ares3 ? 30 : 0))
                },
                kt = function(n) {
                    r.type = "category";
                    r.isAllCharge = !1;
                    r.isGridInit = !0;
                    r.currentCategoryItem = _.find(r.srcCatagoryItems, function(t) {
                        return t.id == n.id
                    });
                    y(null);
                    r.setCurrentCategoryChargeItemsPromise().then(function() {
                        r.refreshCurrentCategoryChargeItemsGridData()
                    })
                },
                ei = function(n) {
                    var t = n.sender.value();
                    r.setCurrentSelectCategoryTreeData(t)
                },
                dt = function() {
                    r.type = "all";
                    r.isAllCharge = !0;
                    r.isGridInit = !0;
                    r.currentCategoryItem = null;
                    w.value(0);
                    r.setCurrentSelectCategoryTreeData();
                    r.setAllChargeItems();
                    it();
                    d();
                    var n = a,
                        i = n.tbody;
                    t(i)(r)
                },
                gt = function() {
                    return r.selectedChargeItems.length ? r.selectedChargeItems.every(function(n) {
                        return n.displayOrder != 0
                    }) : !1
                },
                ni = function() {
                    return r.selectedChargeItems.length ? r.selectedChargeItems.every(function(n) {
                        return n.displayOrder != r.currentCategoryChargeItems.length - 1
                    }) : !1
                },
                ti = function() {
                    r.initData().then(function() {
                        ft();
                        bt()
                    })
                },
                ii = function() {
                    i(function() {
                        r.initData().then(function() {
                            w.setDataSource(r.srcSuperCategoryItems);
                            r.currentCategoryChargeItems = [];
                            r.refreshCurrentCategoryChargeItemsGridData()
                        })
                    })
                },
                ri = function() {
                    i.cancel(b);
                    b = i(function() {
                        n.debug("delaySearchTimer is started...")
                    }, 500);
                    b.then(function() {
                        d()
                    })
                },
                d = function() {
                    var u = r.type == "all" ? a : v,
                        n = r.type == "all" ? r.allChargeItems : r.currentCategoryChargeItems;
                    n = n || [];
                    r.status == "启用" ? n = n.filter(function(n) {
                        return !n.isDisabled
                    }) : r.status == "停用" && (n = n.filter(function(n) {
                        return n.isDisabled
                    }));
                    var t = r.searchKeyWord,
                        f = [{
                            field: "pinyin",
                            operator: "contains",
                            value: t
                        }, {
                            field: "itemName",
                            operator: "contains",
                            value: t
                        }],
                        i = new kendo.data.DataSource({
                            data: n,
                            filter: {
                                logic: "or",
                                filters: f
                            }
                        });
                    i.fetch(function() {
                        var n = i.view(),
                            t;
                        n != null && (t = n.map(function(n) {
                            return n
                        }), u.dataSource.data(t))
                    })
                },
                ut = function() {
                    d()
                },
                ui = function() {
                    return r.selectedChargeItems.length && r.isChargeItemEditAllowed && r.currentCategoryItem && !e.isCategoryName(r.currentCategoryItem.itemName)
                },
                fi = function() {
                    return r.isChargeItemEditAllowed && r.currentCategoryItem && !e.isCategoryName(r.currentCategoryItem.itemName)
                };
            (function() {
                r.isAllCharge = !1;
                r.isGridInit = !1;
                r.selectedChargeItems = [];
                r.canChargeItemsUp = gt;
                r.canChargeItemsDown = ni;
                r.initAllChargeItemsGrid = it;
                r.openEditChargeItemDialog = k;
                r.onChangeCurrentCatagory = kt;
                r.onShowAllChargeItems = dt;
                r.onCurrentCategoryChargeItemsUp = ct;
                r.onCurrentCategoryChargeItemsDown = lt;
                r.onChangeCategoryByCurrentCategoryChargeItems = at;
                r.onExportCurrentCategoryChargeItemsExcel = vt;
                r.onExportAllChargeItemsExcel = pt;
                r.refreshCurrentCategoryChargeItemsGridData = ht;
                r.selectChargeItemModule = ii;
                r.onSearchChargeItems = ri;
                r.onChangeStatus = ut;
                r.searchKeyWord = "";
                r.type = "all";
                r.status = "启用";
                s = r.isChargeItemEditAllowed;
                r.isShowChangeCategoryButton = ui;
                r.isShowCreateChargeItemButton = fi;
                ti()
            })()
        }
    }
}]);
practiceModule.directive("practiceChargeitemCategoryEditView", ["$log", "$timeout", "$q", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/charge/practice-chargeItem-category-edit-view.html",
        link: function(n, i) {
            var r = function() {
                n.changeChargeItemCategory()
            };
            (function() {
                n.onChangeCategoryItem = r;
                t(function() {
                    Ares.centerModal(i.closest(".modal-dialog"))
                }, 50)
            })()
        }
    }
}]);
practiceModule.directive("practiceChargeitemEditView", ["$log", "$timeout", "$modal", "$q", "constants", "apptApplyCompleteUtil", function(n, t, i, r, u, f) {
    "use strict";
    return {
        replace: !0,
        restrict: "E",
        templateUrl: "/app/practice/views/charge/practice-chargeitem-edit-view.html",
        link: function(n, i) {
            var o = null,
                u = null,
                s = null,
                v, y = function() {
                    var t = {
                            chargeName: {
                                required: !0,
                                maxlength: 300,
                                chargeItemName: !0
                            },
                            chargeEnglishName: {
                                maxlength: 500,
                                chargeItemEnglishName: !0
                            },
                            chargeCode: {
                                maxlength: 30,
                                chargeItemCode: !0
                            }
                        },
                        r = {
                            chargeName: {
                                required: "请输入项目名称",
                                maxlength: "项目名称不能大于300个字！",
                                chargeItemName: "名称已被使用！"
                            },
                            chargeEnglishName: {
                                maxlength: "项目英文名称不能超过500个字符！",
                                chargeItemEnglishName: "英文名称已被使用！"
                            },
                            chargeCode: {
                                maxlength: "项目编码不能超过30个字符",
                                chargeItemCode: "编码已被使用！"
                            }
                        },
                        u;
                    n.currentChargeItem.chargeItemType == 0 && n.procedureCodeRequired && (t.chargeCode = {
                        required: !0,
                        maxlength: 30,
                        chargeItemCode: !0
                    }, r.chargeCode = {
                        required: "请输入项目编码",
                        maxlength: "项目编码不能超过30个字符",
                        chargeItemCode: "编码已被使用！"
                    });
                    u = Ares;
                    v = u.validateForm(i.find("#chargeItemForm"), t, r)
                },
                l = function() {
                    var n = i.find("#chargeItemForm");
                    return n.valid()
                },
                p = function() {
                    l() && n.saveChargeItem()
                },
                w = function(t) {
                    var i = t.sender.value();
                    n.currentSuperCategory = _.find(n.superCategoryItems, function(n) {
                        return i == n.id
                    });
                    n.categoryItems = n.srcCategoryItems.filter(function(t) {
                        return t.itemSuperCategoryId == n.currentSuperCategory.id
                    });
                    n.currentCategory = n.categoryItems[0]
                },
                b = function(t) {
                    var i = t.sender.value();
                    n.currentDeductionPlan = _.find(n.deductionPlanList, function(n) {
                        return i == n.id
                    })
                },
                k = function() {
                    n.currentDeductionPlan = null
                },
                d = function() {
                    n.deductionPlanList && n.deductionPlanList.length > 0 && (n.currentDeductionPlan = n.deductionPlanList[0])
                },
                g = function() {
                    n.isChargeItemEditAllowed && !e() && (n.currentChargeItem.allowDiscount = !n.currentChargeItem.allowDiscount)
                },
                nt = function() {
                    n.isChargeItemEditAllowed && !e() && (n.currentChargeItem.isDisabled = !n.currentChargeItem.isDisabled)
                },
                tt = function() {
                    n.isChargeItemEditAllowed && !e() && (n.currentChargeItem.allowOrderDiscount = !n.currentChargeItem.allowOrderDiscount)
                },
                it = function() {
                    n.isChargeItemEditAllowed && (n.currentChargeItem.isInDeal = !n.currentChargeItem.isInDeal)
                },
                rt = function() {
                    n.isChargeItemEditAllowed && (n.currentChargeItem.isPriceUpdatable = !n.currentChargeItem.isPriceUpdatable)
                },
                ut = function(t) {
                    if (n.isChargeItemEditAllowed) {
                        var i = (n.currentChargeItem.itemOption & t) == t;
                        n.currentChargeItem.itemOption = i ? n.currentChargeItem.itemOption - t : n.currentChargeItem.itemOption + t
                    }
                },
                ft = function() {
                    if (n.isChargeItemEditAllowed) {
                        var t = n.currentChargeItem;
                        t.isAutoDeduct = !t.isAutoDeduct;
                        t.isAutoDeduct ? (t.deductionSteps && t.deductionSteps.length > 0 && t.chargeDeductionPlanId ? (t.srcDeductionSteps = t.deductionSteps, t.srcChargeDeductionPlanId = t.chargeDeductionPlanId, t.chargeDeductionPlanId = 0, n.srcCurrentDeductionPlan = n.currentDeductionPlan, n.currentDeductionPlan = null, s.value(0)) : t.isDeductionEnabled = !0, s.enable(!1), n.createAutoDeductDeductionStep()) : (s.enable(!0), t.srcChargeDeductionPlanId && t.srcDeductionSteps ? (t.deductionSteps = t.srcDeductionSteps, t.chargeDeductionPlanId = t.srcChargeDeductionPlanId, n.srcCurrentDeductionPlan && (n.currentDeductionPlan = n.srcCurrentDeductionPlan, n.srcCurrentDeductionPlan = null), s.value(t.srcChargeDeductionPlanId)) : t.isDeductionEnabled = !1)
                    }
                },
                et = function(t) {
                    var i = t.sender.value();
                    n.chargeDeductionPlanSelected(i)
                },
                a = function() {
                    var t = n.currentDeductionPlan ? n.currentDeductionPlan.id : 0;
                    s = i.find("#chargeDeductionPlan").kendoDropDownList({
                        dataSource: n.deductionPlanList,
                        dataTextField: "planName",
                        dataValueField: "id",
                        value: t,
                        select: function(t) {
                            var i = this.dataItem(t.item.index());
                            n.currentDeductionPlan = i;
                            n.chargeDeductionPlanSelected(i.id);
                            n.$apply()
                        }
                    }).data("kendoDropDownList");
                    n.currentChargeItem.isAutoDeduct && s.enable(!1)
                },
                c = function() {
                    if (o) {
                        o.setDataSource(n.superCategoryItems);
                        return
                    }
                    o = i.find(".super-category").kendoDropDownList({
                        dataSource: n.superCategoryItems,
                        dataTextField: "itemName",
                        dataValueField: "id",
                        enable: !n.isNewChargeItem,
                        value: n.currentSuperCategory.id,
                        select: function(t) {
                            var i = this.dataItem(t.item.index()),
                                r = i.id;
                            n.currentSuperCategory = _.find(n.superCategoryItems, function(n) {
                                return r === n.id
                            });
                            n.categoryItems = n.currentSuperCategory.id === 0 ? n.srcCategoryItems : n.srcCategoryItems.filter(function(t) {
                                return t.itemSuperCategoryId === n.currentSuperCategory.id
                            });
                            n.currentCategory = n.categoryItems[0];
                            u == null ? h() : u.setDataSource(n.categoryItems);
                            u.value(n.currentCategory ? n.currentCategory.id : 0)
                        }
                    }).data("kendoDropDownList");
                    (!n.isChargeItemEditAllowed || e()) && o && o.enable(!1)
                },
                h = function() {
                    if (u) {
                        u.setDataSource(n.categoryItems);
                        return
                    }
                    var t = n.currentCategory ? n.currentCategory.id : 0;
                    u = i.find(".category").kendoDropDownList({
                        dataSource: n.categoryItems,
                        dataTextField: "itemName",
                        dataValueField: "id",
                        enable: !n.isNewChargeItem,
                        value: t,
                        select: function(t) {
                            var i = this.dataItem(t.item.index());
                            n.currentCategory = i
                        }
                    }).data("kendoDropDownList");
                    (!n.isChargeItemEditAllowed || e()) && u && u.enable(!1)
                },
                ot = function() {
                    n.hasProductList = !0;
                    _.isFunction(n.initSelectProductStatus) && n.initSelectProductStatus();
                    var t = i.parents(".charge-item-edit");
                    t.addClass("has-product-list").children(".modal-dialog").addClass("has-product-list")
                },
                st = function() {
                    r.all([n.getBaseConfig(), n.getBaseData(), n.getCurrentChargeItem(), n.getSubChargeTypeList(), n.getDeductionPlan(), ]).then(function() {
                        return n.isChargeItemEditAllowedWithBp = ht(), n.filterAlipaybpCategory(), n.getFreeFieldInfo()
                    }).then(function() {
                        t(function() {
                            c();
                            h();
                            a()
                        })
                    })
                },
                ht = function() {
                    return e() ? !0 : n.isChargeItemEditAllowed && !n.isParentEnabled
                },
                ct = function(i) {
                    n.currentChargeItem.product = i;
                    var u = n.currentChargeItem.product.product,
                        r = n.currentChargeItem.product.productUnity;
                    n.currentChargeItem.productItemName = r.name + "-" + r.producer + "-" + u.specification;
                    t(function() {
                        c();
                        h()
                    })
                },
                e = function() {
                    return f.isCompleteItemType(n.currentChargeItem.chargeItemType)
                },
                lt = function() {
                    n.hasProductList = !1;
                    o = null;
                    u = null;
                    var t = i.parents(".charge-item-edit");
                    t.removeClass("has-product-list").children(".modal-dialog").removeClass("has-product-list")
                };
            (function() {
                st();
                y();
                n.valid = l;
                n.validAndSave = p;
                n.unBindDeductionPlan = k;
                n.bindFirstDeductionPlan = d;
                n.onChangCurrentSuperCategory = w;
                n.onChangeCurrentDeductionPlan = b;
                n.changeAllowDiscount = g;
                n.changeAllowOrderDiscount = tt;
                n.changeIsChargeEnabled = nt;
                n.changeIsAutoDeduct = ft;
                n.onChargeDeductionPlanChanged = et;
                n.openEditProductChargeItemDialog = ot;
                n.initSuperCategoryDropdownlist = c;
                n.initCategoryDropdownlist = h;
                n.isApptApplyCompleteChargeItem = e;
                n.hasProductList = !1;
                n.addProduct = ct;
                n.changeDataType = lt;
                n.changeIsInDeal = it;
                n.changeItemOption = ut;
                n.changeAllowUpdatePrice = rt;
                n.$watch("currentChargeItem.chargeItemType", function(i) {
                    i != null && (n.currentChargeItem.productItemName = n.currentChargeItem.itemName, n.currentChargeItem.product = n.srcProduct, n.currentProductId = n.currentChargeItem.productId, t(function() {
                        i || a();
                        c();
                        h()
                    }))
                })
            })()
        }
    }
}]);
practiceModule.directive("practiceChargeitemProductEditView", ["$log", "$timeout", function(n, t) {
    "use strict";
    return {
        replace: !0,
        restrict: "E",
        templateUrl: "/app/practice/views/charge/practice-chargeitem-product-edit-view.html",
        controller: "PracticeChargeitemProductEditCtrl",
        link: function(n, i) {
            var u = function() {
                    i.find(".spu-list-content").mCustomScrollbar({
                        scrollButtons: {
                            enable: !1
                        },
                        autoHideScrollbar: !0,
                        scrollInertia: 150,
                        advanced: {
                            updateOnContentResize: !0
                        },
                        mouseWheel: {
                            preventDefault: !0
                        },
                        callbacks: {
                            whileScrolling: function(t) {
                                t.topPct >= 90 && r(n.pageIndex)
                            }
                        }
                    })
                },
                e = function(t) {
                    n.productUnityList = [];
                    var i = window.event ? t.keyCode : t.which;
                    i == 13 && r()
                },
                o = function(t) {
                    n.selCategory = t;
                    n.categoryId = t.id;
                    f()
                },
                f = function() {
                    n.productUnityList = [];
                    r()
                },
                r = function(r) {
                    var u = i.find(".spu-list-content"),
                        f = function(i) {
                            n.isSearching = !1;
                            n.productUnityList = i;
                            t(function() {
                                u.mCustomScrollbar("update");
                                r || u.mCustomScrollbar("scrollTo", "top")
                            })
                        };
                    n.isSearching || (n.isSearching = !0, r ? n.search(r).then(f) : (n.searchedProductList = [], t(function() {
                        u.mCustomScrollbar("update");
                        n.search(r).then(f)
                    }, 500)))
                };
            (function() {
                n.onSearchProduct = r;
                n.onEnter = e;
                n.onSearch = f;
                n.initScrollbar = u;
                n.onProductCategoryChange = o;
                t(function() {
                    u()
                }, 1e3)
            })()
        }
    }
}]);
practiceModule.directive("emrTemplateComponentConfigView", ["$log", "$compile", "$q", "enums", "$filter", "layoutTemplateSvc", function(n, t, i, r, u, f) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/emr-template-config/emr-template-component-config-view.html",
        controller: "EmrTemplateComponentConfigCtrl",
        link: function(n, u) {
            var e = function() {
                    n.fieldInputType = r.FieldInputType;
                    n.systemComponentType = {
                        input: 0,
                        drowDownList: 1,
                        tooth: 2
                    }
                },
                o = function(t) {
                    var i = function(t) {
                        n.selectedField = t;
                        n.selectedField.components || (n.selectedField.components = [])
                    };
                    t.inputType === n.fieldInputType.MedicalRecord_Archive ? n.getArchive().then(function() {
                        i(t)
                    }) : i(t)
                },
                s = function(i) {
                    h(i).then(function(r) {
                        i.childs = r;
                        i.oldName = i.fieldName;
                        n.selectedField = i;
                        var f = u.find("#component-library-box");
                        f && (f.html(""), t(c(i.inputType))(n, function(n) {
                            f.append(n)
                        }))
                    })
                },
                h = function(t) {
                    var r = i.defer(),
                        u = [],
                        o = [n.fieldInputType.RadioButton, n.fieldInputType.CheckBox],
                        e;
                    return t.fieldValue && _.contains(o, t.inputType) ? (e = t.fieldValue.split("|"), f.getChildFieldByFieldCode(t.fieldCode).success(function(n) {
                        angular.forEach(e, function(t) {
                            var r = {
                                    value: t,
                                    fieldCode: Ares.uuidFast(),
                                    optionData: {}
                                },
                                i;
                            n && n.length > 0 ? (i = _.find(n, {
                                enableWhenFieldValue: t
                            }), i && (r.fieldCode = i.fieldCode, r.id = i.id, i.optionData && (r.optionData = JSON.parse(i.optionData)))) : r.fieldCode = Ares.uuidFast();
                            u.push(r)
                        });
                        r.resolve(u)
                    })) : r.resolve(undefined), r.promise
                },
                c = function(t) {
                    var i = "";
                    switch (t) {
                        case n.fieldInputType.InputText:
                            i = '<component-library-input-view ng-if="selectedField.inputType==fieldInputType.InputText" ng-model="selectedField"><\/component-library-input-view>';
                            break;
                        case n.fieldInputType.TextArea:
                            i = '<component-library-textarea-view ng-if="selectedField.inputType==fieldInputType.TextArea" ng-model="selectedField"><\/component-library-textarea-view>';
                            break;
                        case n.fieldInputType.RadioButton:
                            i = '<component-library-radio-view ng-if="selectedField.inputType==fieldInputType.RadioButton" ng-model="selectedField"><\/component-library-radio-view>';
                            break;
                        case n.fieldInputType.CheckBox:
                            i = '<component-library-checkbox-view ng-if="selectedField.inputType==fieldInputType.CheckBox" ng-model="selectedField"><\/component-library-checkbox-view>';
                            break;
                        case n.fieldInputType.PictureUploader:
                        case n.fieldInputType.NamedPictureUploader:
                            i = '<component-library-upload-view ng-if="selectedField.inputType==fieldInputType.NamedPictureUploader ||selectedField.inputType==fieldInputType.PictureUploader" ng-model="selectedField"><\/component-library-upload-view>';
                            break;
                        case n.fieldInputType.MedicalRecord_ChiefComplaint:
                        case n.fieldInputType.MedicalRecord_History:
                        case n.fieldInputType.MedicalRecord_PastHistory:
                        case n.fieldInputType.MedicalRecord_Advice:
                        case n.fieldInputType.MedicalRecord_Comment:
                            i = '<sys-common-input-component-view ng-if="isShowSystemComponent(selectedField.inputType,systemComponentType.input)" ng-model="selectedField"><\/sys-common-input-component-view>';
                            break;
                        case n.fieldInputType.MedicalRecord_OralCheckRecord:
                        case n.fieldInputType.MedicalRecord_RadiologyCheckRecord:
                        case n.fieldInputType.MedicalRecord_DiagnoseRecord:
                        case n.fieldInputType.MedicalRecord_TreatmentAdvice:
                        case n.fieldInputType.MedicalRecord_TreatmentPlan:
                        case n.fieldInputType.MedicalRecord_CureRecord:
                            i = '<sys-common-tooth-component-view ng-if="isShowSystemComponent(selectedField.inputType,systemComponentType.tooth)" ng-model="selectedField"><\/sys-common-tooth-component-view>';
                            break;
                        case n.fieldInputType.MedicalRecord_Archive:
                            i = '<sys-common-dropdown-component-view ng-if="isShowSystemComponent(selectedField.inputType,systemComponentType.drowDownList)" ng-model="selectedField" source="archives" data-text-field="\'itemName\'" data-value-field="\'itemName\'"><\/sys-common-dropdown-component-view>'
                    }
                    return i
                },
                l = function(t, i) {
                    var r = !1;
                    switch (t) {
                        case n.fieldInputType.MedicalRecord_ChiefComplaint:
                        case n.fieldInputType.MedicalRecord_History:
                        case n.fieldInputType.MedicalRecord_PastHistory:
                        case n.fieldInputType.MedicalRecord_Advice:
                        case n.fieldInputType.MedicalRecord_Comment:
                            r = i === n.systemComponentType.input;
                            break;
                        case n.fieldInputType.MedicalRecord_OralCheckRecord:
                        case n.fieldInputType.MedicalRecord_RadiologyCheckRecord:
                        case n.fieldInputType.MedicalRecord_DiagnoseRecord:
                        case n.fieldInputType.MedicalRecord_TreatmentAdvice:
                        case n.fieldInputType.MedicalRecord_TreatmentPlan:
                        case n.fieldInputType.MedicalRecord_CureRecord:
                            r = i === n.systemComponentType.tooth;
                            break;
                        case n.fieldInputType.MedicalRecord_Archive:
                            r = i === n.systemComponentType.drowDownList
                    }
                    return r
                };
            (function() {
                n.onAddLayoutField = o;
                n.onLayoutFieldSelected = s;
                n.isShowSystemComponent = l;
                e()
            })()
        }
    }
}]);
practiceModule.directive("emrTemplateConfigView", ["$log", "$modal", "$q", "enums", "$filter", "aresDialog", "layoutTemplateSvc", "emrCustomizeEditUtil", "aresNotification", function(n, t, i, r, u, f, e, o, s) {
    "use strict";
    return {
        templateUrl: "/app/practice/views/emr-template-config/emr-template-config-view.html",
        controller: "EmrTemplateConfigCtrl",
        link: function(n, h) {
            var c = u("emrTemplateFieldsStr"),
                p = function() {
                    n.allowEditToothFDI = !0;
                    n.currentMedicalRecord = {
                        isShowChiefComplaint: !0,
                        isShowHistory: !0,
                        isShowPastHistory: !0,
                        isShowOralCheckRecordList: !0,
                        oralCheckRecordList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowRadiologyCheckRecordList: !0,
                        radiologyCheckRecordList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowDiagnoseRecordList: !0,
                        diagnoseRecordList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowTreatmentAdviceList: !0,
                        treatmentAdviceList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowTreatmentPlanList: !0,
                        treatmentPlanList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowCureRecordList: !0,
                        cureRecordList: [{
                            fdiToothCodesArray: []
                        }],
                        isShowAdvice: !0
                    };
                    n.fieldInputType = r.FieldInputType;
                    w();
                    a()
                },
                w = function() {
                    e.getMedicalRecordLayoutTemplates().then(function(t) {
                        var i = _.filter(t, function(n) {
                            return n.templateName != "初诊病历" && n.templateName != "复诊病历"
                        });
                        n.templateTypes = [{
                            templateName: "公司级",
                            templateCode: Ares.uuidFast(),
                            isOpenChilds: !0,
                            templates: i
                        }]
                    })
                },
                a = function() {
                    var t = i.defer();
                    return n.defaultFields ? t.resolve(angular.copy(n.defaultFields)) : e.getAllLayoutField(!1).success(function(i) {
                        var u = _.groupBy(i, function(n) {
                                return n.category
                            }),
                            r = [];
                        r.push({
                            fieldName: c("chiefComplaintHistory"),
                            fieldCode: "chiefComplaintHistory",
                            subFields: u.chiefComplaintHistory
                        });
                        r.push({
                            fieldName: c("oralCheck"),
                            fieldCode: "oralCheck",
                            subFields: u.oralCheck
                        });
                        r.push({
                            fieldName: c("diagnoseTreatmentPlan"),
                            fieldCode: "diagnoseTreatmentPlan",
                            subFields: u.diagnoseTreatmentPlan
                        });
                        r.push({
                            fieldName: c("cureAdvice"),
                            fieldCode: "cureAdvice",
                            subFields: u.cureAdvice
                        });
                        r.push({
                            fieldName: c("other"),
                            fieldCode: "other",
                            subFields: u.other
                        });
                        n.defaultFields = r;
                        t.resolve(angular.copy(n.defaultFields))
                    }), t.promise
                },
                l = function(t, i) {
                    n.isShowDetail = !1;
                    t.id > 0 ? e.getMedicalRecordLayoutTemplateByCode(t.templateCode).then(function(r) {
                        i != null && angular.forEach(i.templates, function(n) {
                            n.isActive = n.templateCode == t.templateCode
                        });
                        var f = _.groupBy(r.rootFields, function(n) {
                                return n.category
                            }),
                            u = [];
                        u.push({
                            fieldName: c("chiefComplaintHistory"),
                            fieldCode: "chiefComplaintHistory",
                            subFields: f.chiefComplaintHistory
                        });
                        u.push({
                            fieldName: c("oralCheck"),
                            fieldCode: "oralCheck",
                            subFields: f.oralCheck
                        });
                        u.push({
                            fieldName: c("diagnoseTreatmentPlan"),
                            fieldCode: "diagnoseTreatmentPlan",
                            subFields: f.diagnoseTreatmentPlan
                        });
                        u.push({
                            fieldName: c("cureAdvice"),
                            fieldCode: "cureAdvice",
                            subFields: f.cureAdvice
                        });
                        u.push({
                            fieldName: c("other"),
                            fieldCode: "other",
                            subFields: f.other
                        });
                        t.categories = _.filter(u, function(n) {
                            return n.subFields && n.subFields.length > 0
                        });
                        t.rootFields = r.rootFields;
                        n.selectedTemplate = t
                    }) : (i != null && angular.forEach(i.templates, function(n) {
                        n.isActive = n.templateCode == t.templateCode
                    }), n.selectedTemplate = t)
                },
                b = function() {
                    n.selectedTemplate.isEditTitle = !0
                },
                k = function() {
                    var t = h.find("#template-title-input").val();
                    t ? (n.selectedTemplate.templateName = t, e.saveLayoutTemplate(n.selectedTemplate).success(function() {
                        n.selectedTemplate.isEditTitle = !1
                    })) : s.error("请输入名称")
                },
                v = function() {
                    n.isShowAddComponentDialog ? (n.isShowAddComponentDialog = !1, n.layoutFields = undefined) : a().then(function(t) {
                        n.layoutFields = t;
                        n.isShowAddComponentDialog = !0
                    })
                },
                d = function() {
                    var t = [],
                        i;
                    angular.forEach(n.layoutFields, function(n) {
                        var i = _.filter(n.subFields, {
                            isCheckd: !0
                        });
                        i && i.length > 0 && (t.length == 0 ? t = i : angular.forEach(i, function(n) {
                            t.push(n)
                        }))
                    });
                    t.length > 0 && (i = g(t), e.addLayoutTemplateFields(n.selectedTemplate.id, i).success(function() {
                        l(n.selectedTemplate);
                        v()
                    }))
                },
                g = function(t) {
                    var r = [],
                        i = 1,
                        u;
                    return n.selectedTemplate.rootFields && (u = _.max(n.selectedTemplate.rootFields, "seqNum"), u && (i = u.seqNum)), angular.forEach(t, function(u) {
                        var f, e, o;
                        i++;
                        u.newFieldCode = Ares.uuidFast();
                        f = angular.copy(u);
                        f.id = 0;
                        f.templateId = n.selectedTemplate.id;
                        f.templateCode = n.selectedTemplate.templateCode;
                        f.srcFieldCode = u.fieldCode;
                        f.parentCode = null;
                        f.seqNum = i;
                        f.fieldCode = u.newFieldCode;
                        f.enableWhenFieldCode && (e = _.find(t, {
                            fieldCode: f.enableWhenFieldCode
                        }), f.enableWhenFieldCode = e ? e.newFieldCode : null);
                        f.subFields && f.subFields.length > 0 && (o = f.subFields.sort(function(n) {
                            return n.enableWhenFieldCode ? 1 : -1
                        }), angular.forEach(o, function(t) {
                            var u, e, s;
                            i++;
                            t.newFieldCode = Ares.uuidFast();
                            u = angular.copy(t);
                            u.id = 0;
                            u.seqNum = i;
                            u.templateId = n.selectedTemplate.id;
                            u.templateCode = n.selectedTemplate.templateCode;
                            u.srcFieldCode = u.fieldCode;
                            u.parentCode = f.fieldCode;
                            u.fieldCode = t.newFieldCode;
                            u.enableWhenFieldCode && (e = _.find(o, {
                                fieldCode: u.enableWhenFieldCode
                            }), u.enableWhenFieldCode = e ? e.newFieldCode : null);
                            u.subFields && u.subFields.length > 0 && (s = u.subFields.sort(function(n) {
                                return n.enableWhenFieldCode ? 1 : -1
                            }), angular.forEach(s, function(t) {
                                var f, e;
                                i++;
                                t.newFieldCode = Ares.uuidFast();
                                f = angular.copy(t);
                                f.id = 0;
                                f.seqNum = i;
                                f.templateId = n.selectedTemplate.id;
                                f.templateCode = n.selectedTemplate.templateCode;
                                f.srcFieldCode = t.fieldCode;
                                f.parentCode = u.fieldCode;
                                f.fieldCode = t.newFieldCode;
                                f.enableWhenFieldCode && (e = _.find(s, {
                                    fieldCode: f.enableWhenFieldCode
                                }), f.enableWhenFieldCode = e ? e.newFieldCode : null);
                                r.push(f)
                            }));
                            u.subFields = [];
                            r.push(u)
                        }), f.subFields = []);
                        r.push(f)
                    }), r
                },
                nt = function(n) {
                    var t = h.find("#templateName_" + n.templateCode);
                    n.templateName = t ? t.val() : "";
                    n.templateName ? e.saveLayoutTemplate(n).success(function(t) {
                        n.id = t.id;
                        n.isEdit = !1
                    }) : s.error("请输入名称")
                },
                tt = function(n, t, i) {
                    if (n) {
                        var r = {
                            templateName: "未命名病例类型",
                            isEdit: !0,
                            templateCode: Ares.uuidFast()
                        };
                        t.templates.push(r);
                        l(r, t)
                    } else i.id > 0 ? i.isEdit = !1 : t.templates = _.filter(t.templates, function(n) {
                        return n.templateCode != i.templateCode
                    })
                },
                it = function(n, t) {
                    if (n && n.id > 0) {
                        var i = "确认要删除【" + n.templateName + "】吗?";
                        f.confirm("提醒", i).then(function() {
                            e.deleteLayoutTemplate(n.id).success(function(i) {
                                i && (t.templates = _.filter(t.templates, function(t) {
                                    return t.id != n.id
                                }))
                            })
                        })
                    }
                },
                rt = function(n, t) {
                    n.isShowBtn = t
                },
                ut = function(t) {
                    n.isShowDetail = !0;
                    angular.forEach(n.selectedTemplate.categories, function(n) {
                        angular.forEach(n.subFields, function(n) {
                            n.isActive = n.fieldCode == t.fieldCode
                        })
                    });
                    var i = angular.copy(t);
                    i.inputType == n.fieldInputType.Group ? e.getChildFieldByParentCodes([t.srcFieldCode]).success(function(n) {
                        var i = angular.copy(t);
                        i.subFields = n;
                        y(i)
                    }) : y(i)
                },
                ft = function(n, t) {
                    var i = _.findIndex(t.subFields, {
                            fieldCode: n.fieldCode
                        }),
                        h;
                    if (!(i <= 0) && t.subFields.length != 1) {
                        var r = t.subFields[i - 1],
                            u = n.id,
                            f = r.id,
                            o = r.seqNum,
                            s = n.seqNum;
                        u > 0 && f > 0 && (h = {
                            ownerId: u,
                            ownerSeqNum: o,
                            otherId: f,
                            otherSeqNum: s
                        }, e.exchangeLayoutTemplateFieldSeqNum(h).success(function(u) {
                            u && (t.subFields[i] = r, t.subFields[i].seqNum = s, t.subFields[i - 1] = n, t.subFields[i - 1].seqNum = o)
                        }))
                    }
                },
                et = function(n, t) {
                    var r = _.findIndex(t.subFields, {
                            fieldCode: n.fieldCode
                        }),
                        i = r + 1,
                        c;
                    if (!(i >= t.subFields.length) && t.subFields.length != 1) {
                        var u = t.subFields[i],
                            f = n.id,
                            o = u.id,
                            s = u.seqNum,
                            h = n.seqNum;
                        f > 0 && o > 0 && (c = {
                            ownerId: f,
                            ownerSeqNum: s,
                            otherId: o,
                            otherSeqNum: h
                        }, e.exchangeLayoutFieldSeqNum(c).success(function(f) {
                            f && (t.subFields[r] = u, t.subFields[r].seqNum = h, t.subFields[i] = n, t.subFields[i].seqNum = s)
                        }))
                    }
                },
                ot = function(n, t) {
                    if (n && n.id > 0) {
                        var i = "确认要删除【" + n.fieldName + "】吗?";
                        f.confirm("提醒", i).then(function() {
                            e.destroyLayoutFieldWithChilds(n.id).success(function(i) {
                                i && (t.subFields = _.filter(t.subFields, function(t) {
                                    return t.fieldCode != n.fieldCode
                                }))
                            })
                        })
                    }
                },
                y = function(t) {
                    n.layoutTemplate = {
                        rootFields: [t]
                    };
                    var i = h.find("#previewContent");
                    o.buildEditEmrHtml(n.layoutTemplate, n, i)
                },
                st = function(n, t) {
                    angular.forEach(t.templates, function(t) {
                        t.isEdit = t.templateCode == n.templateCode
                    })
                },
                ht = function(i) {
                    var r = function(n) {
                            t.open({
                                animation: !0,
                                backdrop: "static",
                                template: "<emr-template-preview-view><\/emr-template-preview-view>",
                                controller: "EmrTemplatePreviewCtrl",
                                windowClass: "width-700-dialog",
                                resolve: {
                                    host: function() {
                                        return {
                                            layoutTemplate: n
                                        }
                                    }
                                }
                            })
                        },
                        u, f;
                    i && i.rootFields && i.rootFields.length > 0 ? (u = _.any(i.rootFields, {
                        inputType: n.fieldInputType.Group
                    }), u ? (f = _.pluck(i.rootFields, "srcFieldCode"), e.getChildFieldByParentCodes(f).success(function(n) {
                        angular.forEach(i.rootFields, function(t) {
                            t.subFields = _.filter(n, {
                                parentCode: t.srcFieldCode
                            })
                        });
                        r(i)
                    })) : r(i)) : s.error("请添加组件")
                },
                ct = function(n) {
                    angular.forEach(n.subFields, function(n) {
                        n.isCheckd = !0
                    })
                };
            (function() {
                n.onTemplateClick = l;
                n.onEditTitle = b;
                n.saveTitle = k;
                n.showAddComponentDialog = v;
                n.addTemplateFields = d;
                n.addTemplate = nt;
                n.isShowTemplateNameEditDialog = tt;
                n.removeTemplate = it;
                n.onTemplateFieldMouseover = rt;
                n.onTemplateLayoutFieldClick = ut;
                n.onMoveDown = et;
                n.onMoveUp = ft;
                n.removeTemplateField = ot;
                n.onTemplateDblclick = st;
                n.showPreviewDialog = ht;
                n.selectAll = ct;
                p()
            })()
        }
    }
}]);
practiceModule.directive("emrTemplatePreviewView", ["$log", "emrCustomizeEditUtil", function(n, t) {
    "use strict";
    return {
        replace: !0,
        templateUrl: "/app/practice/views/emr-template-config/emr-template-preview-view.html",
        link: function(n, i) {
            var r = function() {
                var r = i.find("#previewContent");
                t.buildEditEmrHtml(n.layoutTemplate, n, r)
            };
            (function() {
                r()
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryCheckboxView", ["$log", "$timeout", "layoutTemplateSvc", "$q", "aresNotification", "enums", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-checkbox-view.html",
        scope: {
            ngModel: "=",
            isHideEditBtn: "@?"
        },
        link: function(n) {
            var t = function() {
                    n.ngModel.childs && _.forEach(n.ngModel.childs, function(n) {
                        typeof n._isChecked == "undefined" && (n._isChecked = !1)
                    });
                    n.oldModel = angular.copy(n.ngModel)
                },
                r = function() {
                    var t = n.ngModel.isEditMode;
                    n.ngModel = angular.copy(n.oldModel);
                    n.ngModel.isEditMode = t
                },
                e = function(n, t) {
                    n.inputType = t === "number" ? n.inputType === "number" ? null : "number" : n.inputType === "string" ? null : "string"
                },
                o = function() {
                    if (n.ngModel.childs || (n.ngModel.childs = []), n.ngModel.childs.length >= 20) {
                        u.error("最多添加20个选项");
                        return
                    }
                    var t = Ares.uuidFast();
                    n.ngModel.childs.push({
                        value: "",
                        fieldCode: t,
                        optionData: {},
                        _isChecked: !1
                    })
                },
                s = function(t) {
                    n.ngModel.childs = _.filter(n.ngModel.childs, function(n) {
                        return n.fieldCode !== t.fieldCode
                    })
                },
                h = function(t, i) {
                    if (!(i <= 0) && n.ngModel.childs.length !== 1) {
                        var r = n.ngModel.childs[i - 1];
                        n.ngModel.childs[i] = r;
                        n.ngModel.childs[i - 1] = t
                    }
                },
                c = function(t, i) {
                    if (!(i >= n.ngModel.childs.length) && n.ngModel.childs.length !== 1) {
                        var r = n.ngModel.childs[i + 1];
                        n.ngModel.childs[i] = r;
                        n.ngModel.childs[i + 1] = t
                    }
                },
                l = function() {
                    if (n.ngModel.oldName && n.ngModel.oldName.length > 20) {
                        u.error("标题长度不能超过20字符");
                        return
                    }
                    n.ngModel.fieldName = n.ngModel.oldName;
                    var t = a();
                    i.saveLayoutFieldList(t).success(function(t) {
                        var i, r;
                        t && t.length > 0 && (n.ngModel.isEditMode = !1, !n.ngModel.id > 0 && (i = _.find(t, {
                            fieldCode: n.ngModel.fieldCode
                        }), i && (n.ngModel.id = i.id)), r = _.filter(n.ngModel.childs, function(n) {
                            return n.inputType === "number" || n.inputType === "string"
                        }), angular.forEach(r, function(n) {
                            if (!n.id > 0) {
                                var i = _.find(t, {
                                    fieldCode: n.fieldCode
                                });
                                i && (n.id = i.id)
                            }
                        }))
                    })
                },
                a = function() {
                    var r = function(n) {
                            var t = _.pluck(n, "value");
                            return t.join("|")
                        },
                        u = function(t, i) {
                            _.each(n.ngModel.childs, function(n) {
                                var r = {
                                    id: n.id,
                                    fieldCode: n.fieldCode,
                                    optionData: JSON.stringify(n.optionData),
                                    category: t.category,
                                    parentCode: t.parentCode,
                                    enableWhenFieldCode: t.fieldCode,
                                    enableWhenOperator: 5,
                                    enableWhenFieldValue: n.value
                                };
                                n.optionData && n.optionData.inputType === "number" ? (r.valueType = 1, r.inputType = f.FieldInputType.NumericUpDown, i.push(r)) : n.optionData && n.optionData.inputType === "string" && i.push(r)
                            })
                        },
                        i = [],
                        t = {};
                    return t.id = n.ngModel.id, t.category = n.ngModel.category, t.fieldCode = n.ngModel.fieldCode, t.fieldName = n.ngModel.fieldName, t.inputType = n.ngModel.inputType, t.parentCode = n.ngModel.parentCode, t.seqNum = n.ngModel.seqNum, t.fieldValue = r(n.ngModel.childs), n.ngModel.fieldValue = t.fieldValue, i.push(t), u(t, i), i
                },
                v = function() {
                    n.ngModel = angular.copy(n.oldModel);
                    n.ngModel.isEditMode = !1
                },
                y = function(t, i) {
                    i._isChecked = t.target.checked;
                    var r = _.filter(n.ngModel.childs, function(n) {
                        return n._isChecked
                    });
                    n.ngModel.selectValue = _.map(r, function(n) {
                        return n.value
                    }).join("|")
                },
                p = function() {};
            (function() {
                n.reset = r;
                n.addChild = o;
                n.onInputTypeChanged = e;
                n.onChildRemove = s;
                n.onChildMoveUp = h;
                n.onChildMoveDown = c;
                n.onSave = l;
                n.onClose = v;
                n.onChecked = y;
                n.hasShowInput = p;
                t()
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryGroupView", ["$log", "$timeout", "$q", "enums", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-group-view.html",
        scope: {
            ngModel: "=",
            sourceData: "@?"
        },
        link: function(n) {
            var t = function(t, i) {
                var r = !1;
                switch (t) {
                    case n.fieldInputType.MedicalRecord_ChiefComplaint:
                    case n.fieldInputType.MedicalRecord_History:
                    case n.fieldInputType.MedicalRecord_PastHistory:
                    case n.fieldInputType.MedicalRecord_Advice:
                    case n.fieldInputType.MedicalRecord_Comment:
                        r = i == n.systemComponentType.input;
                        break;
                    case n.fieldInputType.MedicalRecord_OralCheckRecord:
                    case n.fieldInputType.MedicalRecord_RadiologyCheckRecord:
                    case n.fieldInputType.MedicalRecord_DiagnoseRecord:
                    case n.fieldInputType.MedicalRecord_TreatmentAdvice:
                    case n.fieldInputType.MedicalRecord_TreatmentPlan:
                    case n.fieldInputType.MedicalRecord_CureRecord:
                        r = i == n.systemComponentType.tooth;
                        break;
                    case n.fieldInputType.MedicalRecord_Archive:
                        r = i == n.systemComponentType.drowDownList
                }
                return r
            };
            (function() {
                n.systemComponentType = {
                    input: 0,
                    drowDownList: 1,
                    tooth: 2
                };
                n.fieldInputType = r.FieldInputType;
                n.isShowSystemComponent = t
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryInputView", ["$log", "$timeout", "$q", "layoutTemplateSvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-input-view.html",
        scope: {
            ngModel: "=",
            isHideEditBtn: "@?"
        },
        link: function(n, t) {
            var i = function() {
                    var i = t.find("#field_name_" + n.ngModel.fieldCode);
                    i.val(n.ngModel.fieldName);
                    n.ngModel.isEditMode = !0
                },
                f = function() {
                    var f = t.find("#field_name_" + n.ngModel.fieldCode),
                        i = f.val();
                    if (i && i.length > 20) {
                        u.error("标题长度不能超过20字符");
                        return
                    }
                    n.ngModel.fieldName = i;
                    r.saveLayoutFieldList([n.ngModel]).success(function(t) {
                        t && t.length > 0 && (n.ngModel.isEditMode = !1, !n.ngModel.id > 0 && (n.ngModel.id = t[0].id))
                    })
                },
                e = function() {
                    i();
                    n.ngModel.isEditMode = !1
                },
                o = function() {
                    n.ngModel.isEditMode = !0;
                    var i = t.find("#field_name_" + n.ngModel.fieldCode);
                    i.val(n.ngModel.fieldName)
                };
            (function() {
                n.reset = i;
                n.onSave = f;
                n.onClose = e;
                n.onEdit = o
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryRadioView", ["$log", "$timeout", "layoutTemplateSvc", "$q", "aresNotification", "enums", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-radio-view.html",
        scope: {
            ngModel: "=",
            isHideEditBtn: "@?"
        },
        link: function(n) {
            var t = function() {
                    n.oldModel = angular.copy(n.ngModel)
                },
                r = function() {
                    var t = n.ngModel.isEditMode;
                    n.ngModel = angular.copy(n.oldModel);
                    n.ngModel.isEditMode = t
                },
                e = function(n, t) {
                    n.inputType = t == "number" ? n.inputType == "number" ? null : "number" : n.inputType == "string" ? null : "string"
                },
                o = function() {
                    if (n.ngModel.childs || (n.ngModel.childs = []), n.ngModel.childs.length >= 20) {
                        u.error("最多添加20个选项");
                        return
                    }
                    var t = Ares.uuidFast();
                    n.ngModel.childs.push({
                        value: "",
                        fieldCode: t,
                        optionData: {}
                    })
                },
                s = function(t) {
                    n.ngModel.childs = _.filter(n.ngModel.childs, function(n) {
                        return n.fieldCode != t.fieldCode
                    })
                },
                h = function(t, i) {
                    if (!(i <= 0) && n.ngModel.childs.length != 1) {
                        var r = n.ngModel.childs[i - 1];
                        n.ngModel.childs[i] = r;
                        n.ngModel.childs[i - 1] = t
                    }
                },
                c = function(t, i) {
                    if (!(i >= n.ngModel.childs.length) && n.ngModel.childs.length != 1) {
                        var r = n.ngModel.childs[i + 1];
                        n.ngModel.childs[i] = r;
                        n.ngModel.childs[i + 1] = t
                    }
                },
                y = function(t) {
                    n.ngModel.selectValue = t
                },
                l = function() {
                    if (n.ngModel.oldName && n.ngModel.oldName.length > 20) {
                        u.error("标题长度不能超过20字符");
                        return
                    }
                    n.ngModel.fieldName = n.ngModel.oldName;
                    var t = a();
                    i.saveLayoutFieldList(t).success(function(t) {
                        var i, r;
                        t && t.length > 0 && (n.ngModel.isEditMode = !1, !n.ngModel.id > 0 && (i = _.find(t, {
                            fieldCode: n.ngModel.fieldCode
                        }), i && (n.ngModel.id = i.id)), r = _.filter(n.ngModel.childs, function(n) {
                            return n.inputType == "number" || n.inputType == "string"
                        }), angular.forEach(r, function(n) {
                            if (!n.id > 0) {
                                var i = _.find(t, {
                                    fieldCode: n.fieldCode
                                });
                                i && (n.id = i.id)
                            }
                        }))
                    })
                },
                a = function() {
                    var r = function(n) {
                            var t = _.pluck(n, "value");
                            return t.join("|")
                        },
                        u = function(t, i) {
                            var r = _.filter(n.ngModel.childs, function(n) {
                                return n.optionData && n.optionData.inputType == "number"
                            });
                            r && r.length > 0 && angular.forEach(r, function(n) {
                                var r = {};
                                r.id = n.id;
                                r.fieldCode = n.fieldCode;
                                r.optionData = JSON.stringify(n.optionData);
                                r.category = t.category;
                                r.parentCode = t.parentCode;
                                r.valueType = 1;
                                r.inputType = f.FieldInputType.NumericUpDown;
                                r.enableWhenFieldCode = t.fieldCode;
                                r.enableWhenOperator = 5;
                                r.enableWhenFieldValue = n.value;
                                i.push(r)
                            })
                        },
                        e = function(t, i) {
                            var r = _.filter(n.ngModel.childs, function(n) {
                                return n.optionData && n.optionData.inputType == "string"
                            });
                            r && r.length > 0 && angular.forEach(r, function(n) {
                                var r = {};
                                r.id = n.id;
                                r.fieldCode = n.fieldCode;
                                r.optionData = JSON.stringify(n.optionData);
                                r.category = t.category;
                                r.parentCode = t.parentCode;
                                r.enableWhenFieldCode = t.fieldCode;
                                r.enableWhenOperator = 5;
                                r.enableWhenFieldValue = n.value;
                                i.push(r)
                            })
                        },
                        i = [],
                        t = {};
                    return t.id = n.ngModel.id, t.category = n.ngModel.category, t.fieldCode = n.ngModel.fieldCode, t.fieldName = n.ngModel.fieldName, t.inputType = n.ngModel.inputType, t.parentCode = n.ngModel.parentCode, t.seqNum = n.ngModel.seqNum, t.fieldValue = r(n.ngModel.childs), n.ngModel.fieldValue = t.fieldValue, i.push(t), u(t, i), e(t, i), i
                },
                v = function() {
                    n.ngModel = angular.copy(n.oldModel);
                    n.ngModel.isEditMode = !1
                };
            (function() {
                n.reset = r;
                n.addChild = o;
                n.onInputTypeChanged = e;
                n.onChildRemove = s;
                n.onChildMoveUp = h;
                n.onChildMoveDown = c;
                n.onSave = l;
                n.onClose = v;
                t()
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryTextareaView", ["$log", "$timeout", "$q", "layoutTemplateSvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-textarea-view.html",
        scope: {
            ngModel: "=",
            isHideEditBtn: "@?"
        },
        link: function(n, t) {
            var i = function() {
                    var i = t.find("#field_name_" + n.ngModel.fieldCode);
                    i.val(n.ngModel.fieldName);
                    n.ngModel.isEditMode = !0
                },
                f = function() {
                    var f = t.find("#field_name_" + n.ngModel.fieldCode),
                        i = f.val();
                    if (i && i.length > 20) {
                        u.error("标题长度不能超过20字符");
                        return
                    }
                    n.ngModel.fieldName = i;
                    r.saveLayoutFieldList([n.ngModel]).success(function(t) {
                        t && t.length > 0 && (n.ngModel.isEditMode = !1, !n.ngModel.id > 0 && (n.ngModel.id = t[0].id))
                    })
                },
                e = function() {
                    i();
                    n.ngModel.isEditMode = !1
                },
                o = function() {
                    n.ngModel.isEditMode = !0;
                    var i = t.find("#field_name_" + n.ngModel.fieldCode);
                    i.val(n.ngModel.fieldName)
                };
            (function() {
                n.reset = i;
                n.onSave = f;
                n.onClose = e;
                n.onEdit = o
            })()
        }
    }
}]);
practiceModule.directive("componentLibraryUploadView", ["$log", "$timeout", "enums", "layoutTemplateSvc", "aresNotification", function(n, t, i, r, u) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/component-library-upload-view.html",
        scope: {
            ngModel: "=",
            isHideEditBtn: "@?"
        },
        link: function(n) {
            n.fieldInputType = i.FieldInputType;
            var f = function() {
                    n.ngModel.oldName = n.ngModel.fieldName;
                    n.oldModel = angular.copy(n.ngModel)
                },
                t = function() {
                    var t = n.ngModel.isEditMode;
                    n.ngModel = angular.copy(n.oldModel);
                    n.ngModel.isEditMode = t
                },
                e = function() {
                    t();
                    n.ngModel.isEditMode = !1
                },
                o = function() {
                    if (n.ngModel.inputType == n.fieldInputType.NamedPictureUploader && !n.ngModel.oldName) {
                        u.error("请输入标题");
                        return
                    }
                    n.ngModel.fieldName = n.ngModel.oldName;
                    r.saveLayoutFieldList([n.ngModel]).success(function(t) {
                        t && t.length > 0 && (n.ngModel.isEditMode = !1, !n.ngModel.id > 0 && (n.ngModel.id = t[0].id))
                    })
                };
            (function() {
                n.reset = t;
                n.onSave = o;
                n.onClose = e;
                f()
            })()
        }
    }
}]);
practiceModule.directive("emrTemplateLayoutFieldTreeView", ["$log", "$timeout", "$filter", "$q", "$modal", "layoutTemplateSvc", "enums", "aresDialog", function(n, t, i, r, u, f, e, o) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/emr-template-layout-field-tree/emr-template-layout-field-tree-view.html",
        scope: {
            onAddClick: "&",
            onFieldSelected: "&"
        },
        link: function(n, t) {
            var s = i("emrTemplateFieldsStr"),
                v = function() {
                    n.fieldInputType = e.FieldInputType;
                    n.systemComponentType = {
                        input: 0,
                        drowDownList: 1,
                        tooth: 2
                    };
                    n.allComponents = [{
                        name: "单行文本框",
                        inputType: n.fieldInputType.InputText,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "多行文本框",
                        inputType: n.fieldInputType.TextArea,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "单选题",
                        inputType: n.fieldInputType.RadioButton,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "复选题",
                        inputType: n.fieldInputType.CheckBox,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "上传图片",
                        inputType: n.fieldInputType.PictureUploader,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "上传命名图片",
                        inputType: n.fieldInputType.NamedPictureUploader,
                        fieldCode: Ares.uuidFast()
                    }, {
                        name: "组合控件",
                        inputType: n.fieldInputType.Group,
                        fieldCode: Ares.uuidFast()
                    }, ];
                    y()
                },
                y = function() {
                    f.getAllLayoutField(!0).success(function(t) {
                        var r = _.groupBy(t, function(n) {
                                return n.category
                            }),
                            i = [];
                        i.push({
                            isOpenChilds: !0,
                            fieldName: s("chiefComplaintHistory"),
                            fieldCode: "chiefComplaintHistory",
                            subFields: r.chiefComplaintHistory
                        });
                        i.push({
                            fieldName: s("oralCheck"),
                            fieldCode: "oralCheck",
                            subFields: r.oralCheck
                        });
                        i.push({
                            fieldName: s("diagnoseTreatmentPlan"),
                            fieldCode: "diagnoseTreatmentPlan",
                            subFields: r.diagnoseTreatmentPlan
                        });
                        i.push({
                            fieldName: s("cureAdvice"),
                            fieldCode: "cureAdvice",
                            subFields: r.cureAdvice
                        });
                        i.push({
                            fieldName: s("other"),
                            fieldCode: "other",
                            subFields: r.other
                        });
                        n.layoutFields = i;
                        h(i[0].subFields[0])
                    })
                },
                p = function(n, t) {
                    t.stopPropagation();
                    n.isOpenChilds = !n.isOpenChilds
                },
                h = function(t, i) {
                    if ((r(i), t.inputType === n.fieldInputType.Group && (t.isOpenChilds = !t.isOpenChilds), !t.isActive) && (c(), l(), t.isActive = !0, _.isFunction(n.onFieldSelected) && t.inputType != n.fieldInputType.Group)) n.onFieldSelected({
                        field: t
                    })
                },
                c = function() {
                    for (var t, r, u = function(n) {
                            for (var t, r, i = 0; i < n.subFields.length; i++)
                                if (t = n.subFields[i], r = _.find(t.subFields, {
                                        isEdit: !0
                                    }), r) {
                                    r.isEdit = !1;
                                    break
                                } else t.subFields && t.subFields.length > 0 && u(t)
                        }, i = 0; i < n.layoutFields.length; i++)
                        if (t = n.layoutFields[i], r = _.find(t.subFields, {
                                isEdit: !0
                            }), r) {
                            r.isEdit = !1;
                            break
                        } else t.subFields && t.subFields.length > 0 && u(t)
                },
                l = function() {
                    for (var t, r, u = function(n) {
                            for (var t, r, i = 0; i < n.subFields.length; i++)
                                if (t = n.subFields[i], r = _.find(t.subFields, {
                                        isActive: !0
                                    }), r) {
                                    r.isActive = !1;
                                    r.isEditMode = !1;
                                    break
                                } else t.subFields && t.subFields.length > 0 && u(t)
                        }, i = 0; i < n.layoutFields.length; i++)
                        if (t = n.layoutFields[i], r = _.find(t.subFields, {
                                isActive: !0
                            }), r) {
                            r.isActive = !1;
                            break
                        } else t.subFields && t.subFields.length > 0 && u(t)
                },
                w = function(n, t) {
                    (t.stopPropagation(), n.isDefault) || (n.isEdit = !0)
                },
                b = function(n) {
                    var t = window.event ? n.keyCode : n.which;
                    t == 13 && c()
                },
                k = function(t, i) {
                    var u, r;
                    if (i.stopPropagation(), u = _.find(t.subFields, {
                            fieldName: "未命名组件"
                        }), !u) {
                        c();
                        l();
                        var s = Ares.uuidFast(),
                            h = e.FieldInputType.Group,
                            f = 1,
                            o = _.max(t.subFields, "seqNum");
                        if (o && (f = o.seqNum + 1), r = {
                                fieldCode: s,
                                fieldName: "未命名组件",
                                seqNum: f,
                                inputType: h,
                                category: t.fieldCode,
                                isEdit: !0,
                                isActive: !0,
                                isDefault: !1
                            }, t.subFields.push(r), _.isFunction(n.onAddClick)) n.onAddClick({
                            field: r
                        })
                    }
                },
                d = function(n, t, i) {
                    i.stopPropagation();
                    var r = "确认要删除【" + n.fieldName + "】吗?";
                    o.confirm("提醒", r).then(function() {
                        var r = n.id;
                        r > 0 ? f.deleteLayoutField(r).success(function(r) {
                            r && (t.subFields = _.filter(t.subFields, function(t) {
                                return t.fieldCode != n.fieldCode
                            }), t.subFields.length > 0 && h(t.subFields[t.subFields.length - 1], i))
                        }) : (t.subFields = _.filter(t.subFields, function(t) {
                            return t.fieldCode != n.fieldCode
                        }), t.subFields.length > 0 && h(t.subFields[t.subFields.length - 1], i))
                    })
                },
                g = function(n, t) {
                    (t.stopPropagation(), n.newFieldName) && (n.fieldName = n.newFieldName, n.oldName = n.fieldName, f.saveLayoutFieldName(n).success(function() {
                        n.isEdit = !1
                    }))
                },
                nt = function(n, i) {
                    i.stopPropagation();
                    n.isShowAddGroupBox = !n.isShowAddGroupBox;
                    var r = t.find("#group_name_" + n.fieldCode);
                    r.val("")
                },
                tt = function(n, t) {
                    t.stopPropagation();
                    n.isEdit = !1
                },
                r = function(n) {
                    n != null && n.stopPropagation()
                },
                it = function(t, i, u) {
                    r(i);
                    t.components = u ? _.filter(angular.copy(n.allComponents), function(t) {
                        return t.inputType !== n.fieldInputType.Group
                    }) : angular.copy(n.allComponents);
                    t.isShowAddComponentDialog = !t.isShowAddComponentDialog
                },
                a = function(t, i) {
                    r(i);
                    t.components = angular.copy(n.allComponents);
                    t.isShowAddComponentDialog = !1
                },
                rt = function(t, i) {
                    var e, o, u, s;
                    r(i);
                    e = _.filter(t.components, {
                        isCheckd: !0
                    });
                    t.subFields || (t.subFields = []);
                    o = t.subFields.length + 1;
                    e && e.length > 0 && (u = [], s = [n.fieldInputType.InputText, n.fieldInputType.TextArea, n.fieldInputType.RadioButton, n.fieldInputType.CheckBox, n.fieldInputType.PictureUploader, ], angular.forEach(e, function(n) {
                        var i = {
                            seqNum: o,
                            category: t.category,
                            fieldName: n.name,
                            fieldCode: Ares.uuidFast(),
                            inputType: n.inputType,
                            parentCode: t.fieldCode
                        };
                        _.includes(s, i.inputType) && (i.fieldName = "");
                        u.push(i);
                        o++
                    }), u && u.length > 0 && f.saveLayoutFieldList(u).success(function(n) {
                        angular.forEach(n, function(n) {
                            t.subFields.push(n)
                        });
                        a(t)
                    }))
                },
                ut = function(n, t, i) {
                    var u, l;
                    if (r(i), u = _.findIndex(t.subFields, {
                            fieldCode: n.fieldCode
                        }), !(u <= 0) && t.subFields.length != 1) {
                        var e = t.subFields[u - 1],
                            o = n.id,
                            s = e.id,
                            h = e.seqNum,
                            c = n.seqNum;
                        o > 0 && s > 0 && (l = {
                            ownerId: o,
                            ownerSeqNum: h,
                            otherId: s,
                            otherSeqNum: c
                        }, f.exchangeLayoutFieldSeqNum(l).success(function(i) {
                            i && (t.subFields[u] = e, t.subFields[u].seqNum = c, t.subFields[u - 1] = n, t.subFields[u - 1].seqNum = h)
                        }))
                    }
                },
                ft = function(n, t, i) {
                    var e, u, a;
                    if (r(i), e = _.findIndex(t.subFields, {
                            fieldCode: n.fieldCode
                        }), u = e + 1, !(u >= t.subFields.length) && t.subFields.length != 1) {
                        var o = t.subFields[u],
                            s = n.id,
                            h = o.id,
                            c = o.seqNum,
                            l = n.seqNum;
                        s > 0 && h > 0 && (a = {
                            ownerId: s,
                            ownerSeqNum: c,
                            otherId: h,
                            otherSeqNum: l
                        }, f.exchangeLayoutFieldSeqNum(a).success(function(i) {
                            i && (t.subFields[e] = o, t.subFields[e].seqNum = l, t.subFields[u] = n, t.subFields[u].seqNum = c)
                        }))
                    }
                },
                et = function(n, t) {
                    r(t);
                    var i = angular.copy(n);
                    f.getChildFieldByParentCodes([i.fieldCode]).success(function(n) {
                        i.subFields = n;
                        var t = u.open({
                            animation: !0,
                            backdrop: "static",
                            template: "<emr-template-preview-view><\/emr-template-preview-view>",
                            controller: "EmrTemplatePreviewCtrl",
                            windowClass: "width-700-dialog",
                            resolve: {
                                host: function() {
                                    return {
                                        layoutField: i
                                    }
                                }
                            }
                        })
                    })
                },
                ot = function(n, t) {
                    r(t);
                    n.isShowBtn = !0
                },
                st = function(n, t) {
                    r(t);
                    n.isShowBtn = !1
                },
                ht = function(n, t, i) {
                    r(i);
                    var u = "确认要复制【" + n.fieldName + "】吗?";
                    o.confirm("提醒", u).then(function() {
                        var i = angular.copy(n);
                        i.fieldName = i.fieldName + "_副本";
                        i.isDefault && (i.fieldName = s(n.fieldName) + "_副本", i.isDefault = !1);
                        f.copyLayoutField(i).success(function(i) {
                            n.isActive = !1;
                            t.subFields.push(i);
                            h(i)
                        })
                    })
                };
            (function() {
                n.stopPropagation = r;
                n.onCategoryItemClick = p;
                n.onChildItemClick = h;
                n.onChildItemDblclick = w;
                n.onEnterEvent = b;
                n.addLayooutField = k;
                n.removeChildItem = d;
                n.showAddGroupBox = nt;
                n.addGroupToChild = g;
                n.closeGroupToChild = tt;
                n.showAddComponentDialog = it;
                n.onCloseComponentDialog = a;
                n.onAddComponents = rt;
                n.onMoveDown = ft;
                n.onMoveUp = ut;
                n.showPreviewDialog = et;
                n.onChildItemMouseover = ot;
                n.onChildItemMouseleave = st;
                n.copyChildItem = ht;
                v()
            })()
        }
    }
}]);
practiceModule.directive("sysCommonDropdownComponentView", ["$log", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/sys-common-component/sys-common-dropdown-component-view.html",
        scope: {
            ngModel: "=",
            source: "=",
            dataTextField: "@?",
            dataValueField: "@?"
        },
        link: function(n, t) {
            var i = function() {
                var i = n.dataTextField || "itemName",
                    r = n.dataValueField || "itemName";
                n.$watch("source", function() {
                    n.source && t.find("#archive").kendoMultiSelect({
                        dataSource: n.source,
                        dataTextField: i,
                        dataValueField: r
                    }).data("kendoMultiSelect")
                })
            };
            (function() {
                i()
            })()
        }
    }
}]);
practiceModule.directive("sysCommonInputComponentView", ["$log", "$timeout", "$filter", "$q", "aresNotification", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/sys-common-component/sys-common-input-component-view.html",
        scope: {
            ngModel: "="
        },
        link: function() {
            (function() {})()
        }
    }
}]);
practiceModule.directive("sysCommonToothComponentView", ["$log", "$timeout", "$filter", "$q", "aresNotification", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/emr-template-config/child-components/sys-common-component/sys-common-tooth-component-view.html",
        scope: {
            ngModel: "="
        },
        link: function() {
            (function() {})()
        }
    }
}]);
var practice;
(function() {
    "use strict";
    var n = function() {
        function n() {
            this.restrict = "E";
            this.replace = !0;
            this.template = '\n            <div class="schedule-rule-view-new" style="width: 100%; height: 100%;">\n                <ares-new-home-view target-route="charge.thirdPartyDevices" style="height: 100%"><\/ares-new-home-view>\n            <\/div>\n        '
        }
        return n.$inject = [], n
    }();
    practiceModule.directive("ares3ThirdPartyPayDevicesView", Ares.tsDirective(n))
})(practice || (practice = {}));
practiceModule.directive("practicePaymentTypeNewView", ["aresModalShelf", "dataDicSvc", "aresDialog", "appNav", "aresNotification", "paymentTypeSvc", function(n, t, i, r, u, f) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/payment-type/practice-payment-type-new-view.html",
        controller: "PracticePaymentTypeNewCtrl",
        scope: {
            isUpgradeEnabled: "=",
            isUpgradeUnstart: "=",
            isUpgradeStart: "=",
            isUpgradeComplete: "=",
            isInitUpgraded: "=",
            isNewPaymentTypeEnabled: "=",
            hasEditPermission: "=",
            isCustomCategoryEnabled: "=",
            switchPage: "=",
            isShowUpgradeCompleteInfo: "=",
            isUseParentChargeItem: "=",
            isForceNewReportEnabled: "="
        },
        link: function(n) {
            var t = function(n) {
                    n.isShowPaymentTypes = !n.isShowPaymentTypes
                },
                e = function(t) {
                    n.deletePaymentTypePromise(t).then(function() {
                        n.onPaymentTypeChanged(t, !0)
                    })
                },
                o = function(t, i) {
                    var r = n.hasEditPermission && n.isUpgradeComplete && n.isNewPaymentTypeEnabled && (!n.isUseParentChargeItem || n.isUseParentChargeItem && t.isSyncExcluded == !0);
                    return r && i && !n.isUseParentChargeItem && n.forbiddenEnabledPaytypes.indexOf(t.name) >= 0 ? (u.error("所选支付方式不可禁用"), !1) : (i || (r = r && !t.isDisabled), r)
                },
                s = function() {
                    r.goToState("financev2")
                },
                h = function(t) {
                    i.confirm("提示", "确定要删除分组（" + t.name + "）？").then(function() {
                        f.deletePaymentTypeCategory(t.id).then(function() {
                            var i = _.findIndex(n.paymentTypeCategories, function(n) {
                                return n.id == t.id
                            });
                            i >= 0 && n.paymentTypeCategories.splice(i, 1)
                        })
                    })
                };
            (function() {
                n.showOrHideCategoryPaymentTypes = t;
                n.deletePaymentType = e;
                n.isEditEnabled = o;
                n.switchToFinanceReport = s;
                n.deletePaymentTypeCategory = h
            })()
        }
    }
}]);
practiceModule.directive("practicePaymentTypeOldView", ["$q", "$window", "aresDialog", "aresNotification", function(n, t, i, r) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/payment-type/practice-payment-type-old-view.html",
        controller: "PracticePaymentTypeOldCtrl",
        scope: {
            isUpgradeEnabled: "=",
            isUpgradeUnstart: "=",
            isUpgradeStart: "=",
            isUpgradeComplete: "=",
            isInitUpgraded: "=",
            isNewPaymentTypeEnabled: "=",
            hasEditPermission: "=",
            onUpgradeStart: "=",
            switchPage: "=",
            isForceNewReportEnabled: "=",
            isUseParentChargeItem: "="
        },
        link: function(i, u) {
            var f = function() {
                    i.pageViewStatus = {
                        selectedPaymentType: null,
                        selectedIndex: -1,
                        moving: !1,
                        editing: !1,
                        canMoveUp: function() {
                            return !this.moving && i.paymentTypes && i.paymentTypes.length > 1 && this.selectedIndex > 0
                        },
                        canMoveDown: function() {
                            return !this.moving && i.paymentTypes && (i.paymentTypes.length > 1 && this.selectedIndex > -1 && this.selectedIndex < i.paymentTypes.length - 2 || this.selectedIndex == i.paymentTypes.length - 2 && i.paymentTypes[i.paymentTypes.length - 1].id != 0)
                        }
                    };
                    var n = angular.element(t).height() - 188;
                    u.find("#list-body").css("height", n)
                },
                e = function(n, t) {
                    n.id && (i.paymentTypes.forEach(function(n) {
                        n.selected = !1
                    }), n.selected = !0, i.pageViewStatus.selectedPaymentType = n, i.pageViewStatus.selectedIndex = t)
                },
                o = function(n) {
                    if (i.onPaymentTypeEdit()) {
                        var t = i.paymentTypes.indexOf(n);
                        i.deletePaymentTypePromise(n).then(function() {
                            i.paymentTypes.splice(t, 1);
                            i.onCompletePaymentTypeEdit()
                        })
                    }
                },
                s = function() {
                    return i.pageViewStatus.editing ? (r.error("请先保存或取消未保存的支付方式！"), !1) : (i.pageViewStatus.editing = !0, !0)
                },
                h = function() {
                    return i.pageViewStatus.editing = !1, !0
                },
                c = function() {
                    if (i.onPaymentTypeEdit()) {
                        var n = i.paymentTypes[i.paymentTypes.length - 1],
                            t = {
                                id: 0,
                                name: "",
                                itemType: "收费方式",
                                isDefault: !1,
                                displayOrder: 1e4,
                                paymentTypeConfigs: [{
                                    id: 0,
                                    name: "",
                                    scenario: 1,
                                    isEnabled: !0,
                                    isInCashFlow: !0,
                                    isIncome: !0,
                                    isInPerformance: !0
                                }, {
                                    id: 0,
                                    name: "",
                                    scenario: 2,
                                    isEnabled: !0,
                                    isInCashFlow: !0,
                                    isIncome: !1
                                }, {
                                    id: 0,
                                    name: "",
                                    scenario: 3,
                                    isEnabled: !0,
                                    isInCashFlow: !0,
                                    isIncome: !1
                                }]
                            };
                        t.displayOrder = n && n.displayOrder ? n.displayOrder + 1 : i.paymentTypes.length + 1;
                        i.paymentTypes.push(t)
                    }
                },
                l = function(t) {
                    if (t.name = t.name.trim(), t.name == "") {
                        r.error("请输入支付方式名称！");
                        return
                    }
                    v(t) && i.savePaymentTypePromise(t).then(function(u) {
                        var f = [];
                        t.paymentTypeConfigs.forEach(function(n) {
                            n.name = t.name;
                            n.notes = t.notes;
                            n.paymentTypeId = u.id;
                            f.push(i.updatePaymentTypeConfigPromise(n))
                        });
                        f.length > 0 ? n.all(f).then(function() {
                            t.id = u.id;
                            t.viewStatus = "show";
                            i.getPaymentTypes();
                            i.onCompletePaymentTypeEdit()
                        }, function() {
                            r.error("支付方式配置保存失败！")
                        }) : (t.id = u.id, t.viewStatus = "show", i.getPaymentTypes(), i.onCompletePaymentTypeEdit())
                    }, function() {
                        r.error("支付方式保存失败！")
                    })
                },
                a = function(n) {
                    i.paymentTypes.splice(n, 1);
                    i.onCompletePaymentTypeEdit()
                },
                v = function(n) {
                    var t, u;
                    if (i.defaultPaymentTypeNames.indexOf(n.name) >= 0) return r.error("系统默认支付方式不允许手动添加！"), !1;
                    if (t = i.paymentTypes.find(function(t) {
                            return t.id && t.name == n.name
                        }), t) return r.error("已存在支付方式：" + n.name + "！"), !1;
                    if (u = i.paymentTypes.find(function(t) {
                            return t.id && t.code == n.code
                        }), u && n.code) {
                        r.error("已存在编码为" + n.code + "的支付方式！");
                        return
                    }
                    return !0
                },
                y = function(n, t) {
                    var u = i.hasEditPermission && (i.isUpgradeUnstart || i.isUpgradeComplete && !i.isNewPaymentTypeEnabled) && (!i.isUseParentChargeItem || i.isUseParentChargeItem && n.isSyncExcluded == !0);
                    return u && t && !i.isUseParentChargeItem && i.forbiddenEnabledPaytypes.indexOf(n.name) >= 0 ? (r.error("所选支付方式不可禁用"), !1) : (t || (u = u && !n.isDisabled), u)
                },
                p = function(n) {
                    return i.defaultPaymentTypeNames.indexOf(n.name) >= 0
                };
            (function() {
                i.isDefaultType = p;
                i.onPaymentTypeEdit = s;
                i.onCompletePaymentTypeEdit = h;
                i.deletePaymentType = o;
                i.selectPaymentType = e;
                i.addPaymentType = c;
                i.saveFullPaymentType = l;
                i.cancelSaveFullPaymentType = a;
                i.isEditEnabled = y;
                f()
            })()
        }
    }
}]);
practiceModule.directive("practicePaymentTypeUpgradeView", ["$log", "$timeout", "$modal", "$state", "$q", "$location", "$anchorScroll", "appNav", "enums", "eventAggregator", "aresDialog", "aresNotification", "aresModalShelf", function(n, t, i, r, u, f, e, o, s, h, c, l, a) {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/payment-type/practice-payment-type-upgrade-view.html",
        scope: {
            onUpgradeComplete: "=?",
            paymentTypeCategories: "=",
            allPaymentTypes: "=",
            createOrEditPaymentType: "=",
            onUpgradeCancel: "=?",
            unknownPaymentTypes: "=",
            createOrEditPaymentTypeCategory: "=",
            isForceNewReportEnabled: "=",
            switchPage: "=",
            hasEditPermission: "=",
            isUseParentChargeItem: "="
        },
        controller: "PracticePaymentTypeUpgradeCtrl",
        link: function(n) {
            var r = function(t) {
                    var r = a.open({
                        template: "<payment-type-create-dialog-view><\/payment-type-create-dialog-view>",
                        controller: "PaymentTypeCreateDialogCtrl",
                        title: "升级支付方式",
                        confirmClose: !1,
                        resolve: {
                            host: function() {
                                return {
                                    paymentTypeCategories: n.paymentTypeCategories,
                                    allPaymentTypes: n.paymentTypes,
                                    unknownPaymentTypes: n.unknownPaymentTypes,
                                    paymentType: t,
                                    action: "upgrade",
                                    defaultPaymentTypeNames: n.defaultPaymentTypeNames
                                }
                            }
                        }
                    });
                    r.switchTab(0);
                    r.result.then(function() {
                        i();
                        n.checkIsUpgradeComplete()
                    }, function() {
                        i();
                        n.checkIsUpgradeComplete()
                    })
                },
                i = function() {
                    var t = n.moveUpgradedPaymentType();
                    t > 0 && n.refreshPaymentTypeCache()
                },
                u = function(t) {
                    c.confirm("提示", "确定要删除支付方式（" + t.name + "）？").then(function() {
                        n.deletePaymentTypePromise(t).then(function() {
                            l.success("删除成功！")
                        })
                    })
                },
                f = function(t) {
                    n.createOrEditPaymentType && _.isFunction(n.createOrEditPaymentType) && n.createOrEditPaymentType(t)
                },
                e = function() {
                    c.confirm("提示", "取消升级后，将会保留本次升级操作产生的所有设置。下次进入可继续当前的设置进度。确认取消吗？").then(function() {
                        n.cancelUpgrade().then(function() {
                            n.onUpgradeCancel && _.isFunction(n.onUpgradeCancel) && n.onUpgradeCancel()
                        }, function() {
                            l.error("取消失败，请联系系统管理员")
                        })
                    })
                },
                o = function(n) {
                    n.isShowPaymentTypes = !n.isShowPaymentTypes
                },
                s = function() {
                    n.isShowUnknownPaymentTypes = !n.isShowUnknownPaymentTypes
                },
                h = function(t, i) {
                    var r = n.hasEditPermission && (!n.isUseParentChargeItem || n.isUseParentChargeItem && t.isSyncExcluded == !0);
                    return r && i && !n.isUseParentChargeItem && n.forbiddenEnabledPaytypes.indexOf(t.name) >= 0 ? (l.error("所选支付方式不可禁用"), !1) : (i || (r = r && !t.isDisabled), r)
                },
                v = function() {
                    t(function() {
                        n.paymentTypeCategories && n.paymentTypeCategories.length > 0 && n.paymentTypeCategories.forEach(function(n) {
                            n.isShowPaymentTypes = !0
                        })
                    }, 1e3)
                };
            (function() {
                n.isShowUnknownPaymentTypes = !0;
                n.upgradePaymentType = r;
                n.deletePaymentType = u;
                n.editPaymentType = f;
                n.onCancelUpgradeHandler = e;
                n.showOrHideCategoryPaymentTypes = o;
                n.showOrHideUnknownPaymentTypes = s;
                n.isEditEnabled = h;
                v()
            })()
        }
    }
}]);
practiceModule.directive("practicePaymentTypeView", ["aresModalShelf", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/payment-type/practice-payment-type-view.html",
        controller: "PracticePaymentTypeCtrl",
        link: function(n) {
            var r = function() {
                    n.isUpgradeStart = !0;
                    n.isUpgradeUnstart = !1;
                    n.isShowOld = !1
                },
                u = function() {
                    n.isUpgradeStart = !1;
                    n.isUpgradeUnstart = !0
                },
                f = function() {
                    n.isUpgradeStart = !1;
                    n.isUpgradeUnstart = !1;
                    n.isUpgradeComplete = !0;
                    n.isShowUpgradeCompleteInfo = !0;
                    n.isShowNew = !0;
                    n.isUpgradeComplete = !0;
                    n.isNewPaymentTypeEnabled = !0
                },
                e = function() {
                    n.isShowOld = !n.isShowOld;
                    n.isShowNew = !n.isShowNew;
                    n.isShowUpgrade = !n.isShowUpgrade
                },
                t = function() {
                    return n.isUpgradeUnstart || n.isUpgradeComplete && n.isShowOld || n.isForceNewReportEnabled && n.isShowOld
                },
                i = function() {
                    return n.isUpgradeComplete && n.isShowNew
                },
                o = function() {
                    return n.isUpgradeStart && !t() && !i()
                };
            (function() {
                n.onUpgradeStart = r;
                n.onUpgradeCancel = u;
                n.onUpgradeComplete = f;
                n.switchPage = e;
                n.isShowOldPaymentType = t;
                n.isShowNewPaymentType = i;
                n.isShowUpgradePaymentType = o
            })()
        }
    }
}]);
practiceModule.directive("practiceSystemconfigChargeView", ["$log", "$timeout", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/practice-systemconfig/practice-systemconfig-charge-view.html",
        controller: "PracticeSystemconfigChargeCtrl",
        link: function() {
            (function() {})()
        }
    }
}]);
practiceModule.directive("practiceSystemconfigDashboardView", ["$log", "$timeout", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/practice-systemconfig/practice-systemconfig-dashboard-view.html",
        controller: "PracticeSystemconfigDashboardCtrl",
        link: function() {
            (function() {})()
        }
    }
}]);
practiceModule.directive("practiceSystemconfigEmrView", ["$log", "$timeout", function() {
    "use strict";
    return {
        restrict: "E",
        templateUrl: "/app/practice/views/practice-systemconfig/practice-systemconfig-emr-view.html",
        controller: "PracticeSystemconfigEmrCtrl",
        link: function() {
            (function() {})()
        }
    }
}]);